Rohan Soni

Writing · October 2026

Put the guardrail in code, not in the prompt

A prompt asks the model to behave. A check in code doesn't depend on it behaving. For any LLM feature where a wrong answer costs the user something, the second one is the only guardrail I count.

The instruction everyone writes

Most LLM products that summarise or analyse a document have a line in the prompt like "only use information from the document" or "always cite your source." The model follows it most of the time, and when it doesn't, nothing tells you.

The output looks the same either way, with a confident answer and a citation attached. A quote that's slightly wrong reads exactly like a quote that's right.

What Redline does instead

Redline is an app I'm building that reads a client agreement for a freelancer and flags the clauses that could hurt them. A flag the user can't trust is worse than no flag, because they'll act on it.

So every flag carries the exact sentence it came from, and before the flag is shown, code checks that sentence word for word against the user's own document. If it doesn't match, the flag is dropped. The model can still get things wrong, but it can't show the user a clause that isn't in their agreement.

The same rule shaped a smaller decision. Redline sometimes needs to say "this could mean…" when a clause has two readings. I didn't want the model deciding when to hedge, because a model's hedging drifts from run to run. So the model returns how ambiguous a clause is and how harmful it could be as separate fields, and code decides whether the hedge wording appears.

The check also decided what to cut

I cut OCR from the first version. A citation that points at text the scanner misread is worthless, and checking a quote against a bad transcription would only give the user false confidence. Redline is only as good as its citations, so anything that weakens a citation can wait.

I was doing this before LLMs

At Mi Pay, a payments app at Xiaomi India, we read bill reminder text messages to find out when a user's bills were due. The parsing was pattern matching, and pattern matching gets things wrong. We didn't trust the parse on its own. Each parsed reminder was checked again when the user went to pay that bill, so a bad read corrected itself at the point of payment instead of sending wrong reminders month after month. More on that here.

The pattern carries over to LLMs. When a system can be wrong in ways the user can't see, check its output against the source before the user sees it.

How I apply it

  • For every LLM output, ask what the user does with it if it's wrong. If the answer is "act on it," it needs a check outside the model.
  • Make the model return structured fields that code can verify, like the source sentence or a severity, rather than finished prose.
  • Let code make the decisions that should be consistent from run to run, like whether to show a flag or whether to hedge.
  • When a check can't be made reliable, cut the feature until it can.