Skip to main content

Build Your Own Model for a Narrow Problem: Tools and Schema Before RAG and LoRA

tutorial•8 min read•Updated:

TL;DR

  • An own trained model is one of the few things a coding agent cannot rebuild from a description. Naval Ravikant even calls training models “the new building software”. That is the skill I am working hardest on right now: building small models for narrow problems and running them cost-effectively.
  • Most narrow problems should not start with training. My order is: a shared test set, then tools, SQL and schema, then retrieval, and LoRA fine-tuning only when the measurements say it pays.
  • Two rules hold the whole thing together. Every step is judged on the same test set by cost per correct answer and latency. And nothing becomes training data before its licence has been checked.

Why an own model, and why narrow

In A Return to Code, published 28 April 2026, Naval argues that pure software is no longer a moat, and that “training AI models is the new building software for however long that lasts”. He is talking about venture-scale models. I am interested in the small end: models that do one narrow job better and cheaper than a general model does.

It is also the second item on the list in software an agent can rebuild is not a moat: an own trained model is one of the few things the rebuilt version would still be missing.

Narrow matters. A general model is very good at most things and rarely the best or cheapest at one specific thing. If the job is specific enough, a small model with the right examples can match it on that job, at lower cost per call and faster. And the examples that make it good are work you have done, not code an agent can write.

But “train a model” is the last step, not the first. Most of the gain usually comes earlier, and the earlier steps are cheaper and easier to undo.

Step 1: write the job and a shared test set

Before choosing any model, I write the job in one sentence and collect real cases with known correct answers. Not synthetic prompts, but questions that actually came in, with answers someone checked.

This test set is shared. Every approach in the steps below is measured against the same cases, so the comparison is fair. I keep it versioned, and every failure I see later becomes a new case. I have described the routing side of this in eval fixture packs and domain fixtures for content and SQL.

For each run I record three numbers:

  1. Correct answers, by a check that is as mechanical as possible.
  2. Cost per correct answer: everything the run cost, divided by the answers that were right. Not price per token.
  3. Latency, at the median and at the slow end, because an answer that arrives too late is not useful to an agent waiting on it.

Without these, every later step is a matter of taste.

Step 2: tools, SQL and schema first

A surprising number of narrow questions have an exact answer in structured data. For those, the best model is often a general one that is not asked to know the answer, only to fetch it: call a tool, or write SQL against a schema it has been given.

I learned this on an AI analytics platform on Databricks, where plain-English questions became validated SQL against governed tables, and successful query patterns were saved as examples for the next question. The quality came less from the model and more from the schema it was given, the validation around the SQL, and the examples it could lean on.

What this step usually involves:

  • A documented schema with clear names, descriptions and allowed values.
  • Tools with narrow inputs and outputs, so a wrong call fails loudly.
  • Validation of the generated query or tool call before it runs.
  • A handful of verified examples in the prompt.

This step is cheap to try and cheap to undo. If it solves the test set, stop here.

Step 3: retrieval where the answer lives in text

Some answers do not live in tables. They live in documents, rules or notes. That is where retrieval belongs: fetch the relevant passages and let the model answer from them, with the source attached.

I add retrieval only for those questions, and keep the scope small. Retrieval over everything makes answers harder to check and easier to get subtly wrong. A narrow index, clear sources and an answer that cites the passage it used are worth more than a big index.

Then I measure again on the same test set. If correct answers go up and cost per correct answer stays acceptable, keep it.

Step 4: check the licence before anything becomes training data

Before the first training run, every source that might become a training example gets a licence check. Data you are allowed to display, query or link is not automatically data you are allowed to train a model on. Terms differ, and they change.

My rule is simple: if the terms are unclear, it stays out of the training set. That includes data I scraped once for analysis, public datasets with unclear reuse terms, and anything that came from another person’s work. Verified examples from my own runs, where I own both the question and the checked answer, are the safest material, and in my experience also the most useful.

Step 5: fine-tune with LoRA, last

If the test set shows that tools, schema and retrieval have stopped improving the result, and the remaining errors are about behaviour, format or domain language, that is when fine-tuning starts to make sense.

For a small builder, that usually means LoRA: low-rank adaptation, where small additional weight matrices are trained while the original model weights stay frozen. It makes tuning a small open model on a narrow task far cheaper than full fine-tuning, and the adapter is small enough to version like any other artefact.

What I hold myself to at this step:

  • Train only on verified, licence-checked examples, never on unchecked model output.
  • Keep the test set out of training. Otherwise the numbers lie.
  • Compare against the best earlier step, not against nothing. The tuned model has to beat tools plus schema plus retrieval on cost per correct answer, and not lose on latency.
  • Promote with a human yes, the same way any other change in my agent stack ships.

If the tuned model does not win, that is a result too. The test set and the verified examples are still the asset, and they are ready for the next attempt or the next base model.

What I am not arguing

I am not saying everyone should train models. Many narrow problems are solved at step 2 and should stay there. I am saying that when a model is the advantage, it should be earned step by step, measured on the same cases each time, and built on data you have the right to use.

Checklist

  • Write the job in one sentence.
  • Collect real cases with checked answers into a versioned, shared test set.
  • Measure correct answers, cost per correct answer and latency on every run.
  • Try tools, SQL and a documented schema first.
  • Add scoped retrieval only where the answer lives in text.
  • Check the licence of every source before it becomes training data.
  • Fine-tune with LoRA last, on verified examples, with the test set held out.
  • Promote the tuned model only if it beats the best earlier step, and only with an explicit yes.

FAQ

When should I fine-tune a model instead of using a general one? When tools, schema and retrieval have stopped improving results on a shared test set, and the remaining errors can be taught with examples. Promote it only if it wins on cost per correct answer and latency.

Why use tools and SQL before retrieval? Because many narrow questions have exact answers in structured data, and a tool call or validated query can be checked.

What is LoRA? Low-rank adaptation: training small extra weight matrices while the base model stays frozen. It makes tuning a small model on a narrow task much cheaper.

What should I check before using data for training? The licence and terms of every source. If they are unclear, leave it out.

Sources: Naval Ravikant, “A Return to Code”, Naval Podcast, 28 April 2026; Edward J. Hu et al., “LoRA: Low-Rank Adaptation of Large Language Models”, 2021.

Tools Used in This Article

This article mentions several tools from my tech stack.