Skip to chapter content
navan✳THE BUILD LABAI ENGINEERING / GUIDE
0/21 read
CHAPTER 09 / 21 · SHAPING MODEL BEHAVIOR

Prompts as application design.

Understand instruction, context, examples, output contracts, and the limits of prompt wording.

BY NAVAN SAMILONG READTHEORY FIRST
01 / FROM THE BEGINNING

Start with the meaning.

A prompt is the information the application supplies for one model call. It may include a task instruction, user input, retrieved evidence, examples, and output requirements. A clear prompt can reduce ambiguity, but it cannot give the model facts it does not have or permissions it should not hold. Think of prompt design as interface design for a probabilistic component.

Separate trusted application instructions from untrusted content. A document retrieved from the web is evidence to analyse, not an instruction that may override the task. The user request can describe what they want, but the application still controls permitted actions and data. Keeping these roles explicit helps both the model and the surrounding software reason about conflicts.

02 / THE SYSTEM

How the idea works.

Start with a precise goal, then specify the evidence and output. For example: answer the user's question using only the numbered passages; cite the passage IDs for factual claims; if the passages do not support an answer, say so. This is more useful than a broad “be accurate.” Put critical constraints where the model can find them and avoid filling the prompt with redundant instructions.

Examples can teach the desired format or distinguish close categories. They should represent the cases that cause confusion, not only easy successes. Too many examples consume context and can steer the model toward copying surface details. Keep examples consistent with the written rule. If a rule says “decline unsupported questions” but every example answers, the model receives conflicting signals.

Prompt wording is a change to application behavior. Version it, evaluate it on holdout cases, and inspect regressions. Repeatedly polishing a prompt against the same handful of examples can overfit just as model tuning can. Some failures need better retrieval, a narrower task, a stronger schema, or human review rather than more elaborate wording.

A prompt can be read as a sequence of roles. The application says what task is authorized and how to handle missing evidence. The user provides the current request. Retrieved documents provide facts to consider. A malicious instruction inside a document is not another application rule, because the document arrived through a lower-trust path. Labels and delimiters make this distinction easier to represent, but the application must still enforce permissions and tool access outside the prompt.

Examples should clarify a decision boundary. If the model often confuses a billing issue with an account-access issue, show one of each and explain the distinguishing clue. If every example is routine, they may teach style without improving the hard cases. Keep a versioned prompt and record which evaluation cases improved or regressed after each change. This turns prompt editing into a measurable product change.

01RulesTrusted task02QuestionUser request03ContextLabelled evidence04ContractExpected output
Keep instructions, user input, and retrieved evidence clearly separated.
03 / PYTHON, EXPLAINED

Follow the code.

prompt-design.py
def make_prompt(question, passages):
    evidence = "\n".join(f'[{p["id"]}] {p["text"]}' for p in passages)
    return (
        "Answer the question using only the numbered evidence. "
        "Cite IDs after factual claims. If evidence is insufficient, say so.\n\n"
        f"Evidence:\n{evidence}\n\nQuestion: {question}"
    )

The function creates one string with a stable instruction, labelled evidence, and the current question. The IDs make citations possible. An empty passages list would leave no evidence, so the caller should normally choose a decline path before making a model call. The function does not itself verify citations; a downstream check must ensure every cited ID was supplied.

The code also shows why prompt construction belongs in application logic rather than scattered string concatenation across routes. One function can be versioned, evaluated, and changed deliberately.

04 / THE BOUNDARY

What the result does not say.

A prompt is not an access-control mechanism. The application must filter documents and tools before they reach the model.

Do not turn a prompt into a long list of contradictory slogans. Specify observable behavior and add examples only when they clarify a real ambiguity.

05 / KEEP THIS

One clear idea.

A prompt defines the model's local task; software and evaluation enforce the wider contract.

THE CODE IN CONTEXT

The AI cookbook

Complete, explained local workflows sit alongside this reading course.

Browse the cookbook
Finished reading?
Built with curiosity. By Navan Sami. ↗AI engineering · From model calls to reliable systems.