Prompt design that works: role, context, input, examples, constraints

A simple, repeatable template for prompts that produce reliable, on-spec outputs.

Well-structured prompts reduce retries, cut costs, and make outputs predictable. Use a small, consistent template: Role, Context, Input, Examples, Constraints, and Output. Keep each part short and concrete. Version your prompts and test them like code.

Template

  1. Role — who the model is and what it optimizes for.
  2. Context — only the facts needed to do the job.
  3. Input — the variable data for this request.
  4. Examples — 1–3 short pairs that show the pattern.
  5. Constraints — hard rules and failure conditions.
  6. Output — exact shape (JSON schema/text spec) and tone.

Example: customer email summarizer

Role:

You are a support triage assistant. Optimize for correctness and brevity.

Context:

Severity levels: P0 (outage), P1 (degraded), P2 (minor). SLA: P0=1h, P1=4h, P2=24h.

Input (variables):

{
  "email_subject": "Checkout failing on mobile",
  "email_body": "Hi, our app crashes when paying with Apple Pay on iOS 17. ..."
}

Examples (few-shot):

Input → Output pairs (keep short):

Input: {"email_subject":"Billing issues", "email_body":"... card declined ..."}
Output: {"severity":"P2","summary":"Card declined due to AVS mismatch","next_step":"Ask for last4 and zipcode; suggest alternate card"}

Constraints:

  • Always return valid JSON matching the schema.
  • Don’t invent order IDs or user data.
  • If uncertain, set severity to P2 and add note.

Output (schema):

{
  "type": "object",
  "properties": {
    "severity": { "type": "string", "enum": ["P0", "P1", "P2"] },
    "summary": { "type": "string" },
    "next_step": { "type": "string" },
    "notes": { "type": "string" }
  },
  "required": ["severity", "summary", "next_step"]
}

Tips

  • Keep each section compact; trim context ruthlessly.
  • Make examples mirror edge cases you care about.
  • Constrain output with JSON schema or grammar when possible.
  • Version prompts and run tests before shipping changes.
  • Measure retries and invalid-output rates as quality signals.

See also: Prompt Engineering as CI and Guardrails Beyond Regex.

Want more detail? Contact us and we'll share implementation notes for your use case.