Why this matters
As a Prompt Engineer, your prompts will face real users, messy data, and unpredictable requests. Edge cases and exceptions are where models often fail: ambiguous questions, conflicting instructions, missing context, outdated facts, rare terms, mixed languages, or unsafe topics. Designing for these scenarios improves reliability, safety, and user trust.
Who this is for
- Prompt Engineers building production-grade assistants or tools.
- Data Scientists evaluating model robustness across domains.
- Product folks defining behavior for failure and uncertainty.
Prerequisites
- Basic prompt patterns (system/content/format instructions).
- Awareness of model limitations (hallucinations, truncation, outdated knowledge).
- Basic evaluation mindset (test cases, acceptance criteria).
Concept explained simply
Edge cases are requests the model didn’t see often in training or that violate assumptions: vague inputs, missing units, mixed languages, novel entities, or conflicting constraints. Exceptions are safety, policy, or capability boundaries that require refusal, clarification, or fallback.
Mental model
Think like an air-traffic controller with checklists: detect anomalies, slow down, confirm, and route safely. Your prompt should guide the model to:
- Detect uncertainty or risk.
- Clarify missing info or choose a safe default.
- Constrain output format and scope.
- Verify and self-check before finalizing.
- Escalate or politely refuse when needed.
Patterns and techniques
1) Detect → Clarify → Constrain → Verify → Escalate
Template
System: You are a careful assistant. When uncertain, ask 1-2 clarifying questions before answering. If unsafe or out-of-scope, explain why and offer safe alternatives. Assistant policy: - Detect: If ambiguity/missing units/mixed language/conflict → flag. - Clarify: Ask concise questions (max 2) or pick documented defaults. - Constrain: Use provided schema; keep answers brief and cite assumptions. - Verify: Self-check for math, dates, units, and contradictions. - Escalate: If still unsure → provide best-effort + uncertainty note or refuse. Output format: - reasoning_summary: one short sentence - action: clarify | answer | refuse - final: the user-facing text
2) Safe defaults and graceful refusals
- When units/locale missing → ask or default to a clearly stated fallback.
- When unsafe or medical/legal advice → refuse and suggest safer alternatives.
- When knowledge may be outdated → state uncertainty and suggest verification path.
3) Self-check prompts
Rubric snippet
Before final answer, silently run checks: - Are assumptions clearly labeled? - Are numbers consistent (units, conversions)? - Did I follow the requested language/format? - Any contradiction or policy risk? If any check fails → revise once.
4) Structured clarifications
Clarification question patterns
- Scope: "Do you want a summary or detailed steps?"
- Units/Locale: "Which currency and tax region should I use?"
- Time: "Which date format/time zone?"
- Language: "Should I reply in English or Spanish?"
5) Long or noisy inputs
- Ask user permission to summarize before answering.
- Process in chunks with a shared outline.
- Enforce a compact output schema to avoid drift.
Worked examples
Example 1: Ambiguous math with missing units
User: "Add 15% tax to 1200" (no currency, unknown region)
Naive prompt (often fails)
System: Compute totals precisely. User: Add 15% tax to 1200.
Risk: Assumes a tax rate without clarifying region; no currency; no rounding rule.
Robust prompt
System: Ask for missing critical info (currency/region) or state a clear default. User: Add 15% tax to 1200. Assistant (expected): - reasoning_summary: Missing currency/region. - action: clarify - final: "Which currency and region should I use? If not specified, I will use USD and simple percentage, total = 1200 * 1.15. Proceed?"
Example 2: Potentially outdated knowledge
User: "What is the current prime rate in Canada?"
Robust pattern
System: If asking for current values, warn about possible outdated knowledge. Assistant: - reasoning_summary: Time-sensitive request. - action: answer - final: "Rates change frequently and may be updated after my last knowledge. I can explain how to find the official current rate and typical factors influencing it. Would you like the process and context?"
Example 3: Mixed language
User: "ÂżPuedes resumir este artĂculo? I need it in English."
Robust pattern
System: Detect language and follow the user's requested output language. Assistant: - reasoning_summary: Input Spanish, output English requested. - action: clarify - final: "I will summarize the Spanish text in English. Please paste the content (or say 'short' for a brief summary, 'detailed' for more depth)."
Example 4: Very long input
User pastes 10,000+ characters and asks: "Give me key risks."
Robust pattern
System: If input is long, summarize first with an outline, then extract risks. Assistant: - reasoning_summary: Lengthy input, risk of truncation. - action: clarify - final: "The text is long. I will first produce a 5-bullet outline, then list top 5 risks with 1-sentence rationale each. OK?"
Exercises
These mirror the exercises below. The quick test is available to everyone; only logged-in users will see saved progress.
Exercise 1 — Clarify missing locale and units
Design a prompt that handles: "Give me the tax on 1200" with unknown region and currency. It should either ask 1–2 concise clarifying questions or apply a documented default and label the assumption. Constrain the output to a short JSON with keys: reasoning_summary, action, final.
Exercise 2 — Out-of-date info fallback
Create a two-step prompt that handles a time-sensitive query: "What is the unemployment rate this month?" The assistant should: (1) detect time sensitivity and either request a date/source or explain limitations; (2) provide a safe, useful response without pretending to have current data.
Checklist before shipping
- Clarifies missing critical info (units, locale, time, scope)
- Explicit safe defaults and refusals are defined
- Self-check step for math, dates, contradictions
- Handles long inputs (summarize → answer)
- Language detection and output language confirmed
- Output schema enforced (predictable format)
- Clear uncertainty notes for time-sensitive facts
Common mistakes and how to self-check
- Skipping clarifications: Add a hard rule to ask max 1–2 concise questions for critical gaps.
- Hidden assumptions: Force the model to label assumptions in the final answer.
- Overlong answers: Constrain outputs with max bullets or word limits.
- Ignoring language: Require explicit "input_language" and "output_language" fields.
- No uncertainty signal: Include an "uncertainty" note for time-sensitive queries.
Practical projects
- Edge-case harness: Build a set of 50 tricky prompts (ambiguous, long, multilingual, conflicting) and a rubric to score clarify/answer/refuse behavior.
- Safety-first assistant: A prompt that triages financial/medical/legal questions to either refuse or provide general, non-advisory info with clear disclaimers.
- Long-text analyzer: A prompt flow that summarizes first, confirms scope, then extracts key risks with a stable JSON schema.
Learning path
- Collect domain edge cases (10–20 examples from real users).
- Define safe defaults and refusal criteria per domain.
- Create a standard clarify → constrain → verify template.
- Design a self-check rubric and embed it in prompts.
- Build a small evaluation set and measure pass rates weekly.
- Iterate on failures; add new cases to your harness.
Mini challenge
Draft a single prompt that can handle both: (a) "Translate to French and summarize in 3 bullets" when given an English paragraph, and (b) "Summarize in English" when given a French paragraph. It must detect input language, confirm the requested output language, and refuse if the text includes sensitive personal data.
Next steps
- Turn your best pattern into a reusable template for your team.
- Expand your edge-case library monthly; keep measuring.
- Integrate uncertainty and safety signals into your product UI.