The 8 Prompt Patterns That Survived My Last 6 Months
1. Role anchoring
Begin every prompt with a concrete persona that mirrors the downstream workflow. In our ticket‑triage agent we use:
You are a B2B SaaS support specialist for AcmeCorp. Your job is to classify incoming tickets, suggest a resolution, and forward ambiguous cases to a human engineer.
This single sentence reduces the model’s sampling space dramatically. In our logs the mis‑classification rate dropped from 12 % to 4 % after tightening the role description. The trick is specificity: mention the product, the audience, and the decision point. Broad roles (“helpful assistant”) leave the model free to wander into policy‑laden or overly verbose territory, which then taxes downstream throttling and costs.
When a role must evolve—say we add a “billing escalation” path—we append a clause rather than replace the whole anchor. The model retains the original grounding while learning the new sub‑task, avoiding the regression observed when we switched from “support agent” to “customer success manager” wholesale.
2. Structured I/O
All downstream services expect deterministic payloads, so we mandate JSON output for any machine‑consumable result. The prompt ends with an explicit schema block:
{
"ticket_id": "",
"category": "",
"confidence": "",
"action": ""
}
We also embed a tiny validation routine in the orchestration layer. If json.loads throws, we inject a corrective prompt:
Your previous response was not valid JSON. Please re‑format exactly as the schema above.
In practice this “fail‑fast, re‑prompt” loop cuts malformed‑payload incidents from roughly 7 % to under 1 % in production, saving retry compute that would otherwise double latency.
3. Refusal scaffold
Models default to answering, even when the request is out‑of‑scope or legally sensitive. We therefore prepend a refusal matrix:
Do not attempt to generate personal data, proprietary code, or medical advice. If the request matches any of these categories, respond with “I’m sorry, I can’t help with that.”
During the first month we observed a 15 % false‑positive refusal rate, which we trimmed by enumerating concrete examples—e.g., “any request containing a social security number pattern.” The scaffold lives in a separate system prompt, making it easy to audit without touching the business logic prompt.
4. Few‑shot rotation
Static few‑shot examples become stale as user queries evolve. We therefore schedule a nightly job that extracts the top‑20 failure cases from the previous 24 hours, crafts concise demonstrations, and swaps them into the prompt template. The rotation algorithm respects a freshness threshold (no example older than 48 hours) and a diversity constraint (no two examples share the same intent label).
Since implementing rotation, the average per‑query token cost fell by 0.3 k due to shorter context windows, while the downstream error rate improved by 2.3 % points. The key insight is that the model benefits more from recent, relevant exemplars than from a large static corpus.
5. Output validators
For every structured response we ship a validator function that checks three dimensions:
- Schema compliance: field presence, type, and allowed enum values.
- Constraint compliance: cross‑field logic, such as
confidence >= 0.5for auto‑resolve actions. - Domain sanity: business‑specific rules, e.g., a discount must never exceed the maximum configured for the user tier.
If any check fails, we package the error details and feed them back to the model with a corrective instruction. This loop runs entirely in the orchestration layer, so the model never sees raw validation code, preserving security and keeping the prompt lean.
6. Retry‑with‑correction
Rather than discarding a faulty output and starting over, we preserve the model’s initial attempt and ask it to amend the specific defect. The corrective prompt follows a template:
Your last output contained the following issue: {error_description}. Please fix it and return only the corrected JSON.
Empirically, a single correction pass resolves 87 % of validation failures, compared to a 45 % success rate when we re‑prompt from scratch. The approach also halves the average token count per query because the model reuses most of its prior reasoning.
7. Lazy elaboration
We explicitly instruct the model to keep responses minimal unless the user requests depth. The prompt includes:
If the user asks a binary question, answer with a single word (“yes” or “no”). Expand only when the user says “explain more” or provides a follow‑up.
This discipline prevents token bloat in high‑throughput chat flows. In a load test simulating 5 k RPS, average response size dropped from 82 tokens to 47 tokens, cutting compute cost by roughly 40 % without affecting user satisfaction scores.
8. Privilege walls
We separate agents by capability tier. The “listener” agent parses user input and produces a sanitized intent object. A downstream “executor” agent, which holds API keys for destructive actions (e.g., database writes), only receives the intent, never the raw user text. Communication occurs over a typed protobuf channel, eliminating prompt‑injection vectors that rely on textual manipulation.
Our audit logs show zero successful injection attempts after the wall was introduced, whereas the previous monolithic design suffered three incidents in the first two weeks of rollout.
9. Metrics‑driven prompting
Prompt engineering cannot be a one‑off art; it must be measured. We log the following KPIs per request:
- Latency: total round‑trip time, broken down into model inference and orchestration.
- Validity rate: percentage of responses passing all validators on first pass.
- Refusal accuracy: true‑positive vs. false‑positive refusal counts.
- Token efficiency: average tokens generated per successful outcome.
Dashboard alerts trigger when any KPI deviates by more than 10 % from its 30‑day moving average. This early‑warning system has helped us catch regressions caused by model updates or prompt drift before they impact customers.
10. Tooling stack considerations
Choosing the right inference provider and orchestration framework is as critical as the prompt itself. Our current stack includes:
- Model API: Anthropic Claude‑3.5 for its consistent refusal handling and lower hallucination rate on domain‑specific queries.
- Orchestration: Modal serverless functions, which give us sub‑millisecond cold starts and built‑in secret management for privilege walls.
- Validation library:
pydanticfor schema enforcement, combined with custom post‑validation hooks for business rules.
When we trialed a cheaper 8‑bit quantized model on Groq, we observed a 15 % rise in malformed JSON, confirming that raw cost savings can backfire without robust validators.
What didn’t survive
After six months of real‑world traffic we retired several “clever” tricks that offered no measurable benefit:
- Generic “think step‑by‑step” preambles—modern Claude and GPT‑4 models already decompose tasks effectively.
- Long negative instruction lists—beyond five “do not” clauses the model starts ignoring them.
- Persona inflation (“pretend you have 30 years of experience”)—produces verbose filler without improving accuracy.
- Monolithic system prompts spanning multiple pages—maintenance overhead exploded, and the prompts drifted, causing contradictory behavior.
Focusing on concrete, measurable patterns yields a stable production pipeline. The eight surviving prompts, bolstered by metrics, validators, and architectural safeguards, form a reproducible foundation for any AI‑augmented service.