Overview
Curated: · Written: · Reviewed:
Prompt Engineering & Prompt Management
In one line
A prompt is a versioned, typed template that runs on a nondeterministic model, so you design it like software: immutable versions, typed variables that fail closed, tests on held-out data, attributable rollouts and rollback. Reach for it when a prompt change must ship without a code deploy but still be traceable and reversible. If the fact or permission comes from elsewhere, the lever is retrieval, a tool, or deterministic code, not wording.
Key definitions
- Prompt version: an immutable registry record (template bytes, variable schema, model revision it was validated against). Every log line carries its ID.
- Typed template: messages built as a list of role-tagged objects with validated variables, never by concatenating role markers into strings.
- Fail closed: a missing, null, oversized or delimiter-like variable raises a typed error before any model call. Never render
Noneor"undefined". - Untrusted data: retrieved pages, emails, ticket bodies and tool output. Delimiters separate it from instructions but do not create a security boundary.
- Held-out set: cases never used to tune the prompt. Only held-out results support a ship decision.
- Behavior contract: the task, output schema, acceptable error rate and forbidden behavior written before any prompt text.
Formulas and complexity
The token budget you check before every call:
Self-consistency cost scales linearly with the sample count:
For a canary, a 5% arm on 200,000 requests is 10,000 requests per day. Compare arms on their own numbers, not the fleet dashboard.
How it works
The request path is a fixed pipeline. Every step that can fail names the version it used.
The model proposes. The application validates syntax and meaning, then the tool layer enforces authorization. The log records the exact prompt version and model that produced the output, so a bad response can be traced and replayed.
When to use and when not to
| Situation | Prompt wording | Use something else |
|---|---|---|
| Output style, format, decision boundaries | Yes, tested on held-out data | |
| Fact that changes (refund policy, prices) | No | Retrieval or lookup tool |
| Exact arithmetic or totals | No | Deterministic code |
| Permission to act on an account | No | Authorization in the tool executor |
| Secret or credential | Never | Tool execution layer |
| Multi-step task needing a verified answer | Partly | Bounded tools, cross-checks |
Traps interviewers probe
- String concatenation of untrusted text. Ticket bodies pasted into the system message can become instructions. Fix: keep roles structural and pass untrusted fields as validated user or data content.
- Tuning on the test set. A 94% dev score followed by 86% holdout, then a patch that reaches 97% on the same 100 cases, shows overfitting to the holdout. Fix: fix a new holdout or report the first holdout result only.
- Trusting a canary that is inside noise. A 0.7-point gap against a 0.3-point band can be real, but the canary arm's own numbers decide. Fix: compare the arms, check cost and latency, and gate on predeclared thresholds.
- Shared cache keys. Keying on the query text alone serves old prompt output and other tenants' answers. Fix: include prompt version, model version and tenant or authorization scope in the key.
- Majority vote over free text. Self-consistency over the whole JSON string never agrees, because the reasoning differs each time. Fix: vote only on the extracted answer field, and never use the vote as authorization.
Interview tips
Open by naming the lever: "This failure needs a deterministic lookup, so the prompt is not the fix." Then describe the registry, the validation and the rollout.
Expected follow-ups:
- How do you test it? Frozen suites, held-out gates, critical non-regression thresholds.
- How do you know a model upgrade broke it? Pin the model, rerun the baseline, compare held-out slices.
- What if a user pastes "ignore previous instructions"? The tool layer rejects the action, whatever the model says.
- Where do secrets live? In the tool execution layer, never in the prompt.
30-second answer outline:
- The prompt is a versioned program at a probabilistic boundary.
- Write the behavior contract, then choose the lever.
- Typed template, fail-closed rendering, structured messages.
- Validate outputs, enforce authorization in tools.
- Gate changes on held-out results, canary with predeclared stops, log the version on every request, roll back atomically.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.