Let the model read, and let your code decide
Why a language model should turn messy input into a structured request, and never set a price, a date or a number itself.
· 4 min read · By WebSurge Technologies
A language model is good at one thing that ordinary software finds hard: reading messy human input. It is much weaker as a source of truth. It can sound sure and be wrong, and the wrong answer looks exactly like the right one. The most reliable AI features we build are designed around that difference.
The rule
The model reads. Your code decides. In practice that means the model is only allowed to turn input (a sentence, a photo, a pasted document) into a structured request, and everything that has consequences is done by code you can test.
- The model decides: what the person seems to be asking for, expressed as fields such as an origin, a destination, a date or a list of ingredients.
- Your code decides: which of those fields are valid, which defaults apply, which limits are enforced, what the price is and what is shown.
Example: a charter search you can type as a sentence
On an aviation project, a visitor types a request in plain English. Claude only turns it into a structured request through a forced tool call, which means the model cannot reply with free text. Our own code then applies the airport list, the defaults, the dates and the limits, and the normal price cards show the result.
The model cannot invent an airport that is not on the list, because the list is checked by code. It cannot make up a price, because it never produces one.
Example: a photo scan that does not invent calories
The same rule shapes the BiteBrunch photo scan. The vision model names the parts of a dish and estimates portions in grams. The server then computes calories from an ingredient dictionary based on USDA data. Because photo estimates are typically 20 to 30 percent off, the answer is shown as a range and labeled as an estimate rather than as a single exact number.
Why this pattern works
- It limits the damage of a wrong answer. A misread sentence produces a wrong request that your validation can reject or the user can notice, not a wrong price that is quietly shown as fact.
- It makes the important part testable. The rules, limits and arithmetic are ordinary code with ordinary tests. You can also test the AI part against a stand-in service, so the test suite never spends money.
- It makes the model replaceable. If the model changes, the contract (a structured request) stays the same.
How to apply it to your product
- List every decision the feature makes. Mark each as “interpretation” (what did the person mean?) or “consequence” (what happens because of it?).
- Give the model only the interpretation tasks, and force a structured output, for example through a tool call or a JSON schema.
- Validate the output on the server before using it, and reject or ask again when it does not fit.
- Show the person what the system understood, so they can see a misreading.
- Add limits and a kill switch, as described in give every AI feature a price tag and an off switch.
Designing the structured request
The quality of this pattern depends on the shape of the request you ask the model to fill in. A few habits make it dependable:
- Use closed lists where you can. If a field can only be one of 30 airports or six product categories, make it an enumeration and reject anything else.
- Allow “unknown”. Give every optional field an explicit empty value, so the model does not feel pushed to guess a date or a quantity that the person never gave.
- Keep units and formats fixed. Ask for grams, not “a handful”, and for ISO dates, not “next Friday”. Your code can do the conversion from a relative phrase if it knows today’s date.
- Validate with a schema. Check the output with a schema library on the server before anything else runs.
What to do when the input is ambiguous
Sometimes the sentence simply does not say enough. Do not let the model fill the gap. Return the fields that were understood, mark the missing ones and let your interface ask for them, or show the defaults that your code applied so that the person can change them. A feature that says “I understood this, please check” is more trustworthy than one that acts on a guess.
Testing the model part
The model is the one part that is not deterministic, so give it a small, honest test set. Collect real examples of what people type, write down the structured request you expect for each and re-run the set whenever the model, the prompt or the schema changes. Count how many fields match. The goal is not perfection but visibility: you should know when a change makes things worse before your visitors do.
Keep reading
- Case study: aviation AI charter search
- Case study: BiteBrunch AI calorie scan
- Our AI integration and agents service
Have a project in mind? Book a free consultation.