← All notes

June 30, 2026

Prompts are for intent. Code is for guarantees.

MLOpsPrompt engineeringProduction MLAI safety

I tried to make an LLM behave using prompts alone. It worked inconsistently. In a safety context, that means it did not work.

I wanted the bots to give concise responses. The obvious approach: tell the model to be concise. So I did. Strongly. Repeatedly. With examples. The result was “mostly concise.” Sometimes it rambled. In a casual app, “mostly” is fine. When inconsistency can mean a crisis question gets a chatty non-answer, “mostly” is a failure.

The fix was not a better prompt

It was deterministic enforcement at the infrastructure layer:

  1. Token counting.
  2. Sentence limiting.
  3. Response truncation as a hard backstop.

The prompt still does its job. It sets the model’s intent. But the code guarantees the constraint. Both are needed, and they do different jobs.

The rule I now apply everywhere

Prompts are for intent. Code is for guarantees.

If a behaviour is nice-to-have, a prompt is enough. If a behaviour is must-have, a hard length cap, a required format, a safety boundary, you back it with deterministic code. You never let a probabilistic system be the only thing standing between you and a requirement you cannot afford to miss.

A surprising amount of prompt-engineering frustration disappears the moment you stop asking the prompt to do code’s job.

Written by Nadeem Yousaf, senior ML engineer. Have a project like this? Send an inquiry →