Back to notes
Prompt systemsGuide6 min

Build a prompt contract for deterministic product behavior

How to make prompts serve a product contract instead of becoming fragile hidden application logic.

Open source doc

Real workflow example

A refund assistant sometimes writes confident answers even when policy data is missing. Support needs consistent behavior.

The prompt contract says: identify policy version, extract customer facts, classify eligibility, cite evidence, and return needs_human_review when required facts are missing. The server validates the schema and blocks unsupported answers.

The assistant becomes predictable because missing information has an explicit output path.

Implementation approach

This guide is anchored in OpenAI Responses API guide. Use the official API behavior as the boundary, then design the surrounding product state so the feature can be reviewed, retried, and improved.

  1. Write the product outcome in one sentence before writing instructions.
  2. List allowed inputs and define what the model must do when required inputs are missing.
  3. Specify the output schema and unacceptable output patterns.
  4. Move calculations, permission checks, and final writes out of the prompt and into code.
  5. Version prompt changes and test them against saved examples.

Code or config snippet when useful

type prompt_contract_deterministic_product_behavior_workflow_state = {
  sourceId: string;
  status: "draft" | "needs_review" | "approved" | "blocked";
  evidence: Array<{ source: string; summary: string }>;
  nextAction: string;
};

Field notes

  • A prompt contract states role, task, inputs, output shape, constraints, and refusal behavior.
  • Determinism improves when code owns rules and the model owns interpretation within those rules.
  • Prompts should be versioned with the workflow they affect.

Mistakes to avoid

  • Do not hide business rules in long prose prompts when code can enforce them.
  • Do not let the model decide final refunds without policy evidence.
  • Do not change prompt contracts without regression examples.

Ready checklist

  • Outcome is explicit
  • Missing-input behavior defined
  • Output schema linked
  • Business rules in code
  • Prompt version tracked

Practical tip

Practical note
A prompt contract should be readable by product, engineering, and support. If only one person understands it, it is too fragile.

Use this as an implementation constraint, not just advice. The interface, server code, and validation path should make the same behavior true.

Apply this to a build
Contact
Bring the product pressure, system constraints, and expected business outcome.
Send the desired outcome, users, current bottleneck, stack, and timeline. I will respond with a practical senior engineering path for the build.