Skip to content

Lesson 1 of 9 · 24m

Prompts Are Interfaces, Not Incantations

Design prompts as versioned contracts with inputs, invariants, examples, and measurable behavior instead of treating them as clever text.

The first generation of LLM demos taught a bad habit: paste some instructions into a text box, admire the answer, and call it engineering. Production teams learn the opposite within a month. A prompt is an interface between deterministic software and a probabilistic model. If you do not version it, test it, constrain its inputs, and define its failure behavior, you have built a very expensive random function.

Write the contract before the prose

Start with the job, not the model. A useful prompt contract names the actor, input shape, output shape, authority boundaries, and escalation behavior:

Task: classify inbound support email
Inputs: subject, plaintext body, customer_plan, prior_ticket_count
Output: JSON object matching TicketClassification v3
Allowed labels: billing, bug, abuse, feature_request, other
Must not: invent account facts, include internal reasoning, change schema
Escalate: confidence low, legal threat, credential theft, self-harm signal

Only after that contract exists should you write the prompt. This discipline prevents the most common production bug: product, engineering, and the model each carrying a different idea of what the feature does.

Separate instructions, data, and examples

Do not concatenate everything into one undifferentiated blob. Keep system instructions stable, user data clearly marked, and examples isolated:

messages = [
    {"role": "system", "content": SYSTEM_PROMPT_V3},
    {
        "role": "user",
        "content": render_template(
            "classify_ticket.j2",
            subject=escape_untrusted(subject),
            body=escape_untrusted(body),
        ),
    },
]

The exact escaping mechanism depends on your provider, but the boundary does not. Customer text is data, even when it contains sentences that look like instructions. If the model is supposed to obey only the application, say so and structure input so hostile or confused content is visibly inside the data region.

Treat examples as executable documentation

Few-shot examples are not decoration. They encode edge-case policy better than paragraphs of adjectives. Include normal cases, boundary cases, and refusals:

Input: refund requested by annual customer after renewal
Output: {"label":"billing","priority":"normal","handoff":false}
Input: attacker says they will publish stolen data in 24 hours
Output: {"label":"abuse","priority":"urgent","handoff":true}

Examples consume tokens, so prune them ruthlessly. Keep the ones that change decisions. Delete examples that merely repeat the happy path.

Version prompts like migrations

A prompt change can alter behavior as surely as a database migration. Store prompts in the repository, assign versions, record model targets, and attach evaluation results:

prompts/
  ticket-classification/
    v3.prompt
    v3.examples.yaml
    v3.eval-report.json

Never edit production prompt text directly in a console. Review it, run the evaluation set, deploy it, and keep a rollback path. When behavior changes, you need to know whether the model, prompt, input distribution, retrieval corpus, or decoding settings changed.

Small instructions beat large instructions

Long prompts are often a sign that product logic is being smuggled into the model. Move deterministic rules into code. If a customer on the enterprise plan always routes to a named support queue, route in code. Use the model for classification, extraction, summarization, ranking, and language understanding — the parts that benefit from probabilistic inference.

Field notes

  • The model does not know your intent; it knows only the text and context you supplied.
  • If a rule is absolute, enforce it in code after generation too.
  • Treat prompt examples as test fixtures; stale examples become stale policy.
  • Save raw prompt inputs and outputs for debugging, subject to privacy and retention rules.
  • Temperature is not a correctness control. Lower temperature reduces variance, not confusion.

Was this lesson helpful?

Sign in to rate