Most AI reliability problems look mysterious from the outside: the model “randomly” changes formatting, forgets a required field, answers in the wrong tone, or makes up details you did not provide.
In practice, a lot of this comes from treating prompts as prose instead of as product requirements. Humans can infer what you meant. Models can only follow the instructions you actually wrote, plus whatever ambiguity you left behind.
A prompt contract is a lightweight way to bring spec thinking into prompting. It is not a legal contract. It is a compact, repeatable structure that makes outputs easier to validate and safer to automate.
What a prompt contract solves
If you use AI casually, you can accept variation. If you use AI inside a workflow, variation becomes downtime: parsers break, customer messages sound inconsistent, or a downstream system receives a value that should never be set automatically.
A prompt contract targets three failure modes:
- Format drift: the model changes headings, adds extra sections, or swaps JSON for plain text.
- Requirement omission: it answers the main question but forgets constraints, fields, or disclaimers you need.
- Unsafe improvisation: it invents facts, takes actions it should not (for example, “refund approved”), or outputs content you cannot use as-is.
The point is not to force perfection. The point is to make it obvious when the model complied, and to reduce how often it fails in predictable ways.
The five parts of a prompt contract
A useful contract fits on one screen. When it grows beyond that, it usually means you are asking one prompt to do multiple jobs. Split tasks before you add more rules.
1) Role and scope
Define who the assistant is and what it is allowed to do. “Helpful” is not a scope. “Summarize customer messages for internal triage” is a scope.
Include a short “not allowed” list for high-risk actions. This can be as simple as “Do not promise refunds or deadlines.”
2) Input contract
State what inputs the model will receive and how to interpret them. This reduces guesswork and discourages the model from inventing missing fields.
- Tell it what fields exist (and which might be missing).
- Tell it what to do with empty values (for example, output
null). - Tell it what is authoritative (for example, “Only use the provided message text; do not assume account status.”).
3) Output contract (schema and style)
Specify output shape and strictness. If a machine will parse it, enforce a machine-readable format and forbid extra text.
You can express this as JSON keys, bullet headings, or a form-like template. The key is that it is testable.
4) Decision rules and refusals
Add explicit rules for ambiguous situations. For example: “If the customer asks for a refund, set needs_human to true.”
Also define refusal behavior: what the model should do when it cannot comply. In automation, “I cannot determine this from the input” is much better than a confident guess.
5) Self-check and evidence
Finally, ask the model to check itself against the contract and provide minimal evidence. Evidence can be:
- A short list of which rules were triggered.
- Quoted snippets from the input that justify a classification.
- A boolean field like
contract_okthat is true only when all required fields are present.
This makes reviews faster and helps you debug failures without re-reading full conversations.
Prompt Contract (template)
- Role: [who it is] and Scope: [what it does, what it never does]
- Inputs: [fields provided], [allowed sources], [how to handle missing]
- Output: [exact format], [required fields], [tone/style constraints]
- Rules: [decision rules], [edge cases], [refusal behavior]
- Self-check: [how to validate], [evidence requirements]
A concrete example: support ticket triage
Imagine a small SaaS team that receives inbound messages through a shared inbox. They want AI to triage tickets into a few categories and draft an internal note. They do not want AI sending messages to customers or making promises.
Here is what a prompt contract could look like conceptually (no code, just the structure):
- Role and scope: “You are a support triage assistant. Classify the issue and draft an internal summary. Do not write customer-facing replies. Do not suggest refunds or timelines.”
- Inputs: “You will receive:
subject,message_body,product_area(optional),customer_tier(optional). Only use these fields.” - Output: JSON only with keys:
category,severity,needs_human,summary,evidence_quotes(array of up to 2 short quotes). No additional keys.” - Rules: “If message includes billing, refunds, legal threats, or account deletion, set
needs_humantrue and severity at least medium.” - Self-check: “If any required field is unknown, set it to
nulland setneeds_humantrue.”
What this buys you is operational clarity. When a ticket is misrouted, you can see whether the model ignored a rule or your contract missed a case.
A copyable checklist for writing contracts
Use this checklist the next time you turn a one-off prompt into something you will run repeatedly.
- Name the job: one sentence that describes the task and the intended audience (internal, customer, editor).
- List the allowed inputs: write the field names and explicitly forbid outside assumptions.
- Choose an output shape: JSON for automation, bullets for humans. State “no extra text” if needed.
- Define “unknown”: specify
null, “unknown”, or an empty string. Do not leave it implicit. - Add hard boundaries: actions the model must never take (commitments, approvals, sensitive claims).
- Write 3 to 7 decision rules: include edge cases that trigger escalation.
- Require minimal evidence: one quote or a short rationale tied to the input.
- Specify tone: “neutral and concise” beats a long paragraph about being professional.
- Define a failure mode: what it should output when the input is insufficient.
- Test with 10 examples: include normal, ambiguous, and adversarial inputs. Save them for regression testing.
If you run prompts as part of a publishing or automation pipeline, keep a small folder of example inputs and expected outputs. That turns “prompt tweaking” into a measurable change rather than guesswork.
Common mistakes and how to fix them
- Mistake: Mixing multiple tasks. Example: “Classify, summarize, propose solution, and write a customer response.”
Fix: Split into two prompts: triage output for systems, then a separate draft that can be reviewed. - Mistake: Asking for “JSON” without specifying keys.
Fix: List required keys, allowed values, and whether extra keys are forbidden. - Mistake: Overly long style rules. Models will comply less reliably as rule count grows.
Fix: Keep style to 2 to 4 bullets. Enforce the rest with downstream checks. - Mistake: No explicit handling of missing data. This encourages fabrication.
Fix: Mandatenullplus escalation if any required value is missing. - Mistake: No evidence requirement. You cannot tell if the output is grounded in the input.
Fix: Ask for one or two short quotes that justify the classification.
When not to use a prompt contract
A prompt contract is best when you care about consistency and can define what “correct” looks like. There are cases where it is the wrong tool.
- Pure brainstorming: If variety is the goal, rigid contracts can reduce creativity. Use looser prompts and human selection.
- High-stakes decisions: If the output would directly approve access, money movement, compliance decisions, or safety outcomes, do not rely on a prompt contract alone. Use dedicated controls and human review.
- Unstable inputs: If your input fields are not well-defined yet, the contract will churn. Stabilize the data model first, then lock the prompt.
In other words, prompt contracts shine when the system around the model is ready to treat outputs as structured artifacts, not as chat.
- A prompt contract is a small spec that makes AI outputs testable: defined inputs, defined outputs, defined failure modes.
- Reliability improves most when you (1) constrain format, (2) define unknowns, and (3) require evidence tied to the input.
- Keep contracts short. If your contract keeps growing, split the task into stages.
- Contracts are not a substitute for risk controls. For high-stakes actions, add human review and system-level guardrails.
Conclusion
Prompting becomes dramatically easier when you stop trying to “say it better” and start writing a contract the model can follow and your systems can validate. A good contract makes errors obvious, reduces rework, and gives you a stable foundation for iterative improvement.
If you publish or automate with AI, treat prompts as part of your product surface area: version them, test them with saved examples, and keep the contract readable enough that a teammate can audit it quickly.
FAQ
Is a prompt contract the same as a system prompt?
No. A system prompt is a placement and priority concept. A prompt contract is the content structure of your instructions. You can put a contract in a system message, a user message, or split across both, as long as the model receives a clear spec.
Should I always force JSON output?
Only when a machine will parse the result or you need strict consistency. For editorial workflows, a structured outline with headings can be easier to review. Choose the format that matches how the output will be consumed.
How do I handle “unknown” fields without losing usefulness?
Use null (or a clearly defined token like “unknown”) and add a companion field like needs_human. That lets your pipeline continue while still routing uncertain cases for review.
How long should a prompt contract be?
As a rule of thumb, one screen. If you need more, it is a sign you should split the task, simplify the output, or move some checks into deterministic validation outside the model.