In many teams a prompt starts life as a string pasted into a file at 11 p.m. before a demo. Months later it has grown to 900 words, nobody remembers why a particular sentence is in capital letters, and changing a single word breaks something unrelated. This is not a failure of prompting. It is the predictable result of treating a critical piece of logic as an informal note rather than as a software artifact.
A prompt is code that runs on a probabilistic interpreter. It deserves the same practices as any other code: version control, review, parameterization, tests and release management. This article lays out those practices and the anti-patterns that undermine them.
A prompt is a component with an interface
Start by writing down the contract of each prompt, as you would for a function.
- Inputs: what variables are injected, their types and maximum sizes, and whether they are trusted.
- Output: the format, schema and allowed values.
- Behavior: what the prompt must always do, never do and do when information is missing.
- Model assumptions: the model, version and parameters (temperature, max tokens) that it was tuned for.
- Owner: the person or team responsible.
When the contract is explicit, you can test it, review changes against it and decide whether a new model is a drop-in replacement. When the contract lives in someone’s head, every change is a gamble.
A prompt without a written contract and a test is a rumor about how the system behaves.
Anatomy of a good prompt
Well-structured prompts tend to share a layout. The order below also happens to suit provider prompt caching, since stable content comes first.
- Role and goal. One or two sentences on who the model is acting as and what success is. Specific beats grand: “You classify inbound support emails for a billing product” is better than “You are a world-class assistant.”
- Rules and constraints. A short, numbered list of requirements, ordered by importance. State what to do rather than only what to avoid.
- Knowledge and context. Policies, glossary, product facts, tool descriptions. Mark clearly where this ends.
- Examples. Two to five representative input-output pairs, including at least one edge case and one example of the correct refusal or “unknown” answer.
- Task input. The variable content, delimited so it cannot be confused with instructions.
- Output format. The schema or template, restated close to the end where it influences generation strongly.
Some practical heuristics that hold up across models:
- Be concrete about format. Show the JSON shape, not just “return JSON.”
- Give the model an exit. “If the email does not mention an invoice, return category unknown” prevents forced guesses.
- Explain the reason behind important rules. Models generalize better from “Do not give legal advice because we are not licensed” than from a bare prohibition.
- Use delimiters such as XML-style tags to separate instructions, documents and user input.
- For multi-step reasoning, ask for a brief rationale or a scratchpad field before the final answer, then discard it from user-facing output.
- Keep few-shot examples diverse. Three nearly identical examples teach the model to copy their surface form.

System prompts versus user prompts
The system prompt is where durable instructions live: role, policy, format, safety rules. The user message carries the variable request. Models are trained to give system instructions more weight, but not absolute authority, so do not rely on the system prompt alone for enforcement.
Guidelines for system prompts:
- Keep them as short as the job allows. Every sentence competes for attention and costs tokens on every call.
- Separate policy that rarely changes from product content that changes often. Compose the final system prompt from modules rather than editing a monolith.
- Never put secrets in a system prompt. Assume users can extract it with enough effort.
- Enforce hard rules in code. If a discount must never exceed 10 percent, validate the output; the prompt is only the first line of defense.
- Test for instruction hierarchy: does a user message saying “ignore your rules” change behavior? Include such cases in your test set.
Templates and versioning
Store prompts as files, not strings
Move prompts out of application code into dedicated files, such as Markdown or YAML with placeholders, kept in the same repository. Benefits include readable diffs, easy review by non-engineers and the ability to load a specific version for replay.
# prompts/classify_ticket/v7.yaml
id: classify_ticket
version: 7
model: provider-model-2026-01 # pinned, dated model identifier
temperature: 0.1
max_tokens: 300
inputs: [ticket_text, product_glossary]
output_schema: schemas/ticket_classification.json
system: |
You classify inbound support tickets for a subscription billing product.
Rules:
1. Choose exactly one category from the list.
2. If the ticket does not fit, use "other". Do not guess.
user: |
<glossary>{{product_glossary}}</glossary>
<ticket>{{ticket_text}}</ticket>
Render templates with a real templating engine and escape or delimit injected content. Never concatenate untrusted text directly into the instruction section.
Version everything that changes behavior
A version should capture the prompt text, model identifier, parameters, schema, examples and any retrieval settings. Log the version with every production call so you can answer “which prompt produced this output?” months later. Use semantic-style bumps: a patch for wording that should not change behavior, a minor for new rules, a major for a schema change.
Pin the model to a specific dated identifier instead of a floating alias. Aliases can change underneath you. When you want to upgrade, treat it as a change with its own pull request and evaluation run.
Release like software
Roll out new prompt versions behind flags, to a small percentage of traffic, and compare metrics with the previous version before expanding. Keep the previous version one flag flip away. For high-risk features, run the new prompt in shadow mode, generating outputs without showing them, and compare.
Testing prompts
Prompt changes cannot be validated by reading them. Build tests at several levels.
| Level | What it checks | Example |
|---|---|---|
| Unit | Single prompt against fixed cases with deterministic assertions | Output parses against schema; category in allowed set |
| Property | Behaviors that must always hold | Never reveals system prompt; always refuses out-of-scope requests |
| Regression | Previously failing inputs stay fixed | The ticket that was misclassified in May |
| Comparative | New version versus current on the same set | Win rate, accuracy per category, cost and latency |
| Adversarial | Injection and abuse attempts | Documents containing instructions; unusual encodings |
Keep a dataset of 50 to 300 realistic cases with expected results or rubrics, and run it in continuous integration whenever a prompt, model or schema file changes. Use exact checks where possible, and a calibrated model-based judge for open-ended qualities. Measure variance by running each case several times; at nonzero temperature a single pass can mislead. A change is real only when the improvement exceeds the noise.
When a bug is reported, the fix procedure should be: add the failing input to the dataset, confirm the test fails, change the prompt, confirm it passes and that nothing else regressed. This is ordinary test-driven discipline, and it prevents the endless oscillation where fixing one case breaks another.
Managing prompt complexity
Prompts grow by accretion. Each incident adds a sentence, and eventually the prompt contradicts itself. Counter this actively.
- Refactor regularly. Review long prompts every quarter. Merge duplicate rules, remove obsolete ones, and check each remaining rule still earns its place by testing without it.
- Decompose. One prompt that classifies, extracts, drafts and checks policy is hard to debug. Splitting into smaller steps, each with its own test set, usually improves reliability and lets you use cheaper models on simple steps. The trade-off is added latency and orchestration.
- Prefer data over prose. Rather than describing a hundred product names in a paragraph, supply a lookup via retrieval or a tool.
- Use examples sparingly but well. Examples are powerful and also expensive in tokens; select them dynamically from a pool by similarity to the current input when the task is varied.
Anti-patterns
- Prompt by incident. Adding a rule for each complaint without a test or a review of existing rules. Result: contradictions and fragile behavior.
- Shouting. Excessive capitals, repeated “VERY IMPORTANT” and threats. It signals missing structure and can cause over-application of a rule.
- Negative-only instructions. A long list of “do not” statements without telling the model what to do instead.
- Unpinned models. Relying on an alias that silently changes, then wondering why quality dropped on a Tuesday.
- Untested “improvements”. Declaring a prompt better after trying three inputs by hand. Anecdotes are the enemy of quality.
- Prompt as security boundary. Trusting instructions alone to protect secrets, permissions or money.
- Hidden state in prompts. Dates, user names or configuration hard-coded into text, which then goes stale and defeats caching.
- Copy-paste prompts across models. A prompt tuned for one model often behaves differently on another. Re-evaluate on every migration.
- Ignoring cost. A 3,000-token system prompt on a call made ten million times a month is a budget line. Measure it.
- No owner. If nobody is accountable for a prompt, nobody maintains it.
Team workflow
Make prompt work visible and reviewable. Pull requests should show the prompt diff, the evaluation results versus baseline and the cost and latency change. Involve domain experts: the support lead often writes a better rule about refund policy than an engineer does, provided the review process and tests protect against regressions. Maintain a short style guide for prompts in the repository, covering layout, delimiters, naming and the checklist for adding a rule. Datainter’s own client projects use a simple checklist at review time: contract updated, test added, model pinned, cost estimated, rollback defined.
Key takeaways
- Write down each prompt’s contract: inputs, output schema, behaviors, model and owner.
- Structure prompts with a stable, cacheable prefix, clear delimiters, a few diverse examples and an explicit exit for unknown cases.
- Store prompts as versioned files, pin dated model identifiers and log the version with every production call.
- Test at multiple levels, run the suite in CI, measure run-to-run variance and turn every bug into a regression case.
- Keep prompts small through regular refactoring and decomposition, and enforce hard rules in code, not in prose.
- Avoid the common anti-patterns: prompting by incident, shouting, unpinned models, untested edits and treating the prompt as a security boundary.

