This prompt is for production engineers who need the model to reject inputs that cannot produce valid structured output. It uses positive and negative example pairs to teach refusal boundaries, distinguishing between fixable format issues and unfixable content gaps. Use this when your pipeline must produce a strict JSON schema and you cannot afford hallucinated fields, silent null fills, or best-guess completions on garbage input. This prompt belongs in extraction, normalization, and API payload generation workflows where downstream systems depend on schema compliance.
Prompt
Counterexample-Driven Refusal Prompt for Invalid Inputs

When to Use This Prompt
Defines the production scenarios where counterexample-driven refusal is the right safety boundary, and when simpler validation or upstream filtering is a better fit.
Deploy this prompt when the cost of a bad output exceeds the cost of no output. Typical triggers include: a downstream database that rejects rows with missing required fields, an API contract that breaks on type mismatches, or a compliance requirement that forbids fabricated values. The prompt is most effective when you can supply at least three positive examples (valid input producing correct structured output) and three negative examples (invalid input producing a structured refusal with a reason code). Do not use this prompt when the input is always well-formed, when a simple JSON Schema validator can catch errors post-generation, or when you can filter invalid inputs upstream with deterministic rules. In those cases, the refusal logic adds token cost and latency without proportional safety gain.
Before wiring this into a production harness, define your refusal contract explicitly. The model should return a consistent refusal structure—such as {"status": "refused", "reason": "...", "input_snippet": "..."}—rather than free-text apologies or empty objects. Pair this prompt with a post-generation validator that checks for the refusal schema and routes refused outputs to a dead-letter queue or human review. If your use case involves regulated data (healthcare, finance, legal evidence), always require human review for refused inputs rather than silently dropping them. Start by running this prompt against a golden dataset of 50–100 inputs that includes known invalid cases, and measure both the refusal rate and the false-refusal rate before promoting to production.
Use Case Fit
Where this prompt works and where it does not. Understand the operational boundaries before deploying a counterexample-driven refusal prompt.
Good Fit: Strict Schema Pipelines
Use when: You have a rigid output contract (JSON, XML) and inputs that are frequently malformed or out-of-domain. The prompt teaches the model to reject unfixable inputs rather than hallucinating fields. Guardrail: Define a clear 'unprocessable' output shape that your parser can distinguish from a successful extraction.
Bad Fit: Open-Ended Chat
Avoid when: The user expects a conversational assistant that should always try to help. Counterexample-driven refusal will make the model feel brittle and unhelpful. Guardrail: Use this pattern only for machine-to-machine flows or when a strict API contract is required.
Required Inputs
What you need: A target schema, a set of valid input-output pairs, and a carefully curated set of invalid inputs that should trigger refusal. Guardrail: Your negative examples must cover missing fields, wrong data types, and out-of-domain content. Without them, the model will default to guessing.
Operational Risk: Over-Refusal
What to watch: The model rejects valid but slightly unusual inputs because they resemble a negative example. This breaks your pipeline's recall. Guardrail: Implement an eval set that measures the refusal rate on a golden dataset of valid inputs. Alert if the rate exceeds a defined threshold (e.g., >2%).
Operational Risk: Refusal Bypass
What to watch: A cleverly phrased invalid input tricks the model into producing a malformed output instead of refusing. Guardrail: Always pair this prompt with a strict output schema validator in your application code. The validator is your last line of defense, not the model's refusal.
Maintenance Burden
What to watch: As your real data drifts, your fixed set of counterexamples becomes stale. New failure modes emerge that the model doesn't recognize. Guardrail: Log all instances where the validator rejects the model's output. Periodically review these logs to identify new negative examples to add to the prompt.
Copy-Ready Prompt Template
A copy-ready prompt that uses positive and negative example pairs to teach the model where the refusal boundary lies for invalid structured output requests.
This prompt template teaches the model to distinguish between fixable format issues and unfixable content gaps by providing explicit counterexamples. Instead of relying on lengthy refusal policies, you supply a schema, a few valid input-output demonstrations, and carefully chosen negative examples where the input cannot satisfy the output contract. The model learns to refuse only when extraction is genuinely impossible, reducing both over-refusal on edge cases and hallucinated completions on impossible requests.
textSystem: You are a strict extraction engine. Your only job is to produce a valid JSON object matching [OUTPUT_SCHEMA] from the provided [INPUT]. Before outputting JSON, you must classify the input as EXTRACTABLE or UNEXTRACTABLE. If EXTRACTABLE, output the JSON. If UNEXTRACTABLE, output a refusal object with a specific reason code from [REFUSAL_REASONS]. Do not hallucinate missing data. Do not refuse fixable formatting issues. [OUTPUT_SCHEMA] { "status": "success" | "refused", "data": { ... } | null, "refusal_reason": string | null } [REFUSAL_REASONS] - MISSING_REQUIRED_FIELD: A field marked required in the schema is absent from the input and cannot be inferred. - CONFLICTING_VALUES: The input contains contradictory information for the same field. - OUT_OF_DOMAIN: The input does not contain the type of information the schema expects. - GARBLED_INPUT: The input is too noisy, truncated, or malformed to parse reliably. [EXAMPLES] --- Input: "Name: Jane Doe, Email: jane@example.com" Output: {"status": "success", "data": {"name": "Jane Doe", "email": "jane@example.com"}, "refusal_reason": null} --- Input: "Call me tomorrow about the project." Output: {"status": "refused", "data": null, "refusal_reason": "MISSING_REQUIRED_FIELD"} --- Input: "Name: John Smith, Email: john@old-company.com, Email: john@new-company.com" Output: {"status": "refused", "data": null, "refusal_reason": "CONFLICTING_VALUES"} --- Input: "The quick brown fox jumps over the lazy dog." Output: {"status": "refused", "data": null, "refusal_reason": "OUT_OF_DOMAIN"} --- Input: "N@me: J%ne D*e, Em@il: jane@@examp le.com" Output: {"status": "refused", "data": null, "refusal_reason": "GARBLED_INPUT"} [INPUT] {{user_input}}
To adapt this template, replace [OUTPUT_SCHEMA] with your exact target schema, including which fields are required. Populate [REFUSAL_REASONS] with the specific failure modes relevant to your domain—avoid generic categories that blur the line between fixable and unfixable. The [EXAMPLES] block is the most critical section: include at least three positive examples showing successful extraction from varied formats, and at least one counterexample per refusal reason. Place the most common failure mode last in the example list to leverage recency effects. When deploying, log every refusal reason code alongside the input to monitor whether your refusal boundary is too strict or too permissive, and iterate on your counterexamples accordingly.
Prompt Variables
Inputs the prompt needs to work reliably. Replace each placeholder before sending the prompt to the model. Validation notes describe how to check the variable value before injection.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[VALID_INPUT_EXAMPLES] | Positive examples showing inputs that should produce structured output | 3-5 JSON objects with input text and expected output schema | Each example must have a valid output that passes the target schema validator. Check for field completeness and type correctness before use. |
[INVALID_INPUT_EXAMPLES] | Counterexamples showing inputs that should trigger refusal | 3-5 JSON objects with input text and refusal response format | Each counterexample must represent an unfixable content gap, not a formatting issue. Verify that no valid output exists for the input before use. |
[OUTPUT_SCHEMA] | The target JSON schema or structured format the model must produce for valid inputs | JSON Schema object or TypeScript interface definition | Validate schema syntax before injection. Schema must include required fields, types, and nullability rules. Test that example outputs pass schema validation. |
[REFUSAL_FORMAT] | The exact refusal response structure the model must return for invalid inputs | JSON object with refusal_reason, confidence, and suggested_action fields | Refusal format must be distinct from valid output format to prevent confusion. Verify that refusal responses can be parsed by downstream error handling code. |
[FIXABLE_BOUNDARY_EXAMPLES] | Examples of inputs with formatting issues that can be corrected vs content gaps that cannot | 2-3 paired examples showing fixable format issues and unfixable content gaps | Each fixable example must have a clear correction path. Each unfixable example must lack essential information. Test that the model distinguishes between the two categories. |
[CONFIDENCE_THRESHOLD] | Minimum confidence score required to produce output instead of refusing | 0.85 | Float between 0.0 and 1.0. Lower values increase false positives. Higher values increase refusal rate. Calibrate against a labeled test set before production deployment. |
[MAX_RETRY_ATTEMPTS] | Number of repair attempts allowed for fixable format issues before escalating to refusal | 2 | Integer >= 0. Set to 0 to disable repair attempts. Each retry consumes tokens and latency. Monitor retry rates in production to detect input quality degradation. |
Implementation Harness Notes
How to wire the counterexample-driven refusal prompt into a production application with validation, retries, logging, and human review gates.
This prompt is designed to sit behind an API endpoint or queue worker that receives unstructured or semi-structured input and must return either a valid structured object or an explicit refusal. The implementation harness must treat the model's output as untrusted until it passes schema validation and refusal-type checks. Because the prompt uses positive and negative example pairs to teach refusal boundaries, the harness should also monitor the refusal rate over time to detect drift in input quality or model behavior.
Wire the prompt into a pipeline with three stages: pre-validation, model invocation, and post-validation. Pre-validation checks for obviously empty inputs, excessive length, or binary garbage that should never reach the model. Model invocation sends the prompt template with the input inserted into the [INPUT] placeholder, using a low-temperature setting (0.0–0.2) to maximize deterministic refusal behavior. Post-validation parses the model response against the expected output schema and checks for a refusal field or equivalent refusal signal. If the output fails schema validation, log the raw response and the input fingerprint, then retry once with an explicit repair prompt before escalating. If the model returns a valid refusal, route the input to a dead-letter queue or human review bucket depending on the [RISK_LEVEL] configuration.
For high-risk domains such as healthcare or finance, add a human review gate for all refusals and for any output where the model's confidence annotation falls below a configured threshold. Log every invocation with the input hash, model version, prompt version, refusal decision, and latency. Use structured logging so you can build a dashboard that tracks refusal rate, schema compliance rate, and retry rate. Set an alert if the refusal rate shifts by more than 20% week-over-week, as this often signals input distribution drift or a model behavior change. Avoid using this prompt for inputs where a best-effort partial extraction is preferable to a hard refusal—this pattern is for workflows where an incorrect structured output is worse than no output at all.
Expected Output Contract
Fields, types, and validation rules for the refusal decision object returned by the counterexample-driven prompt. Use this contract to parse the model response and route accepted or rejected inputs in your application harness.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
decision | string enum: ACCEPT | REJECT | Must be exactly ACCEPT or REJECT. Any other value triggers a retry or fallback to REJECT. | |
reason | string | Must be non-empty when decision is REJECT. Must reference a specific violation from the refusal taxonomy provided in the prompt. Null allowed only when decision is ACCEPT. | |
violation_category | string enum: FORMAT_ERROR | CONTENT_GAP | AMBIGUOUS_INPUT | OUT_OF_SCOPE | null | Must match one of the defined categories when decision is REJECT. Must be null when decision is ACCEPT. Parse check against the allowed enum list. | |
fixable | boolean | Must be true if the input can be corrected by the user (e.g., format error). Must be false if the input is fundamentally incompatible (e.g., out-of-scope content). Used to route to clarification vs. hard refusal. | |
clarification_prompt | string or null | Required when fixable is true. Must contain a specific, actionable question asking the user for the missing or corrected information. Must be null when fixable is false or decision is ACCEPT. | |
extracted_fields | object or null | When decision is ACCEPT, must contain the structured output matching the target schema. When decision is REJECT, must be null. Validate against the target JSON schema on acceptance. | |
confidence | number 0.0-1.0 | Must be a float between 0.0 and 1.0 inclusive. Values below 0.7 with decision ACCEPT should trigger a human review flag. Values above 0.3 with decision REJECT should be logged for potential over-refusal analysis. |
Common Failure Modes
What breaks first when using counterexample-driven refusal prompts and how to guard against it.
Over-Refusal on Borderline Inputs
What to watch: The model rejects valid inputs that contain minor formatting issues, unusual phrasing, or edge-case data because the negative examples were too aggressive. Guardrail: Include borderline-positive examples that show the model accepting inputs with fixable issues while still refusing truly invalid ones. Track refusal rate by input category and set a maximum acceptable refusal threshold for known-good inputs.
Refusal Boundary Drift After Prompt Changes
What to watch: Adding new positive examples or adjusting instructions silently shifts the refusal boundary, causing previously rejected inputs to be accepted or previously accepted inputs to be rejected. Guardrail: Maintain a regression test set of known accept/reject pairs and run it against every prompt version. Flag any change in refusal behavior as a breaking change requiring explicit review.
Counterexample Contamination of Positive Behavior
What to watch: Negative examples that are too similar to valid inputs cause the model to hallucinate problems in clean data or add unnecessary caveats to correct outputs. Guardrail: Audit counterexamples for semantic distance from positive examples. If a counterexample shares more than 50% structural similarity with a positive case, add explicit boundary notes or restructure the example to clarify the distinction.
Silent Compliance Instead of Refusal
What to watch: The model produces a structurally valid output for an invalid input by fabricating missing fields, guessing values, or filling gaps with plausible but incorrect data instead of refusing. Guardrail: Add refusal-specific output validation that checks for explicit refusal signals, null field patterns, or confidence scores below threshold. Log all outputs that pass schema validation but originated from inputs that should have triggered refusal.
Inconsistent Refusal Format Across Model Versions
What to watch: Model upgrades change the phrasing, structure, or field presence of refusal responses, breaking downstream parsers that expect a specific refusal shape. Guardrail: Define a strict refusal output schema with required fields and test it across model versions. Use schema validation on refusal outputs with the same rigor applied to successful extractions. Include refusal format examples in the prompt.
Example Set Staleness for Evolving Input Patterns
What to watch: Production input distributions shift over time, introducing new invalid input patterns that the original counterexamples never covered, causing the model to accept genuinely bad inputs. Guardrail: Monitor refusal rate trends and sample refused vs accepted inputs weekly. When new invalid patterns appear in accepted outputs, add targeted counterexamples and revalidate the full example set against recent production data.
Evaluation Rubric
Run these checks against a golden dataset of at least 50 inputs with known extraction or refusal labels. Each criterion targets a specific failure mode of counterexample-driven refusal prompts.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Valid Input Extraction Accuracy |
| Schema violations, missing required fields, or incorrect field values on inputs that should succeed | Schema validation + field-level exact match against golden dataset valid subset |
Invalid Input Refusal Rate |
| Model produces partial or full structured output on inputs labeled as unfixable or out-of-domain | Output type check: refusal message present AND structured output block absent or empty |
Refusal Format Consistency | 100% of refusals use the specified refusal format with reason code and no hallucinated fields | Refusal message missing reason code, contains extracted fields, or uses non-standard phrasing | Regex match against expected refusal template; assert no JSON output block present |
Boundary Input Handling |
| Model refuses inputs that have minor format issues correctable without content inference | Manual review of boundary subset; compare refusal vs correction decision against labeled expected behavior |
Over-Refusal Detection | <= 5% refusal rate on valid inputs (false positive refusals) | Legitimate inputs with minor noise or variation trigger refusal instead of extraction | Count refusals on valid subset; flag if refusal rate exceeds threshold |
Under-Refusal Detection | <= 5% extraction rate on invalid inputs (false negative refusals) | Inputs with missing required content or out-of-domain topics produce structured output | Count extraction attempts on invalid subset; flag if extraction rate exceeds threshold |
Counterexample Generalization |
| Model fails to refuse novel invalid input patterns that share characteristics with demonstrated counterexamples | Hold-out test set with invalid input categories excluded from prompt examples; measure refusal rate |
Refusal Reason Accuracy |
| Refusal cites wrong reason (e.g., 'missing field' when input is out-of-domain) | Compare refusal reason code against labeled failure category in golden dataset |
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Adapt This Prompt
How to adapt
Start with the base prompt and 3-5 positive/negative example pairs. Use a frontier model (GPT-4o, Claude 3.5 Sonnet) with default temperature. Keep the refusal instruction simple: "If the input cannot produce valid [OUTPUT_SCHEMA], respond with [REFUSAL_FORMAT]."
Watch for
- Over-refusal on borderline inputs that a human could fix
- Under-refusal on inputs missing one required field
- No logging of refusal reasons for later tuning

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us