This prompt is designed for audit, debugging, and compliance systems that need to explain why a conversational AI's internal state changed between turns. The core job-to-be-done is generating a human- and machine-readable diff from two consecutive dialogue state snapshots. The ideal user is an AI engineer or platform developer building observability into a multi-turn assistant, a compliance officer reviewing a decision trace, or a debugging tool that surfaces state anomalies. The required context is a pair of structured state objects (the 'before' and 'after' states) and the specific user utterance that triggered the transition. Without all three inputs, the diff will be speculative.
Prompt
Dialogue State Diff Generation Prompt

When to Use This Prompt
Define the job, reader, and constraints for the Dialogue State Diff Generation Prompt.
Do not use this prompt for real-time state tracking or for generating the state objects themselves. It is a post-hoc analysis tool, not a state manager. It is also not a replacement for a deterministic state machine; use it when the state transition logic is complex, model-driven, or requires natural-language explanations for human review. The prompt is most valuable when state changes are non-obvious—for example, when a user's clarification silently overwrites a previously confirmed slot, or when a topic shift causes a cascade of intent and entity updates that a simple JSON patch would not explain. In high-compliance environments, the output should be treated as a draft requiring human approval before being committed to an official audit trail.
Before wiring this into a production pipeline, ensure your upstream state tracking system reliably captures the before and after snapshots at the correct granularity. A common failure mode is feeding the prompt incomplete state objects that lack the fields the model needs to explain the change. The next section provides the exact prompt template and placeholder definitions. After adapting it, proceed to the implementation harness to add validation, retries, and logging.
Use Case Fit
Where the Dialogue State Diff Generation Prompt delivers value and where it introduces risk. Use these cards to decide if this prompt fits your operational context before integrating it into audit or debugging pipelines.
Good Fit: Compliance Audit Trails
Use when: you need a human- and machine-readable explanation of why dialogue state changed, triggered by which user utterance, for regulated workflows (finance, healthcare, legal). Guardrail: The diff output must be stored alongside the state snapshot and the triggering utterance to create a complete, reviewable audit record.
Good Fit: Developer Debugging Workflows
Use when: debugging multi-turn assistant failures where state corruption is suspected. The diff isolates which turn introduced a bad slot value or dropped a pending action. Guardrail: Pair the diff with a state validation prompt to catch inconsistencies before they propagate across turns.
Bad Fit: Real-Time Inference Paths
Avoid when: the diff generation is on the critical path for user-facing responses. Generating a diff adds latency and token cost. Guardrail: Run diff generation asynchronously or in a sidecar logging pipeline, never blocking the primary assistant response.
Required Inputs: Two Valid State Snapshots
Risk: The prompt cannot function if either the prior or current state snapshot is missing, malformed, or hallucinated. Guardrail: Validate both state objects against their schema before invoking the diff prompt. If validation fails, log the raw state and escalate rather than generating a misleading diff.
Operational Risk: Diff Drift Under High Change Volume
Risk: When many slots change in a single turn, the diff may become verbose, miss subtle changes, or hallucinate a clean explanation for noisy state transitions. Guardrail: Set a maximum slot-change threshold. If exceeded, flag the turn for human review instead of trusting the generated diff.
Operational Risk: Triggering Utterance Ambiguity
Risk: The prompt may attribute state changes to the wrong user turn when multiple turns are processed together or when the user corrects themselves mid-turn. Guardrail: Always provide exactly one user utterance as the trigger context. If the turn contains multiple intents, run intent detection first and isolate the relevant span.
Copy-Ready Prompt Template
A reusable prompt for generating structured diffs between two dialogue state snapshots, explaining what changed, why, and which user utterance triggered the change.
This prompt template is designed for audit, debugging, and compliance systems that need to track dialogue state evolution across turns. It takes two consecutive state snapshots and the user utterance that occurred between them, then produces a human- and machine-readable diff. The output is structured for both developer debugging and automated compliance trace generation. Use this when you need to explain state transitions, not just record them.
textYou are a dialogue state auditor. Your task is to compare two consecutive dialogue state snapshots and explain what changed, why it changed, and which user utterance triggered the change. ## INPUTS ### Previous State (before the user turn) ```json [PREVIOUS_STATE]
Current State (after the user turn)
json[CURRENT_STATE]
User Utterance (the turn that occurred between the two states)
text[USER_UTTERANCE]
State Schema Definition (optional, for field interpretation)
json[STATE_SCHEMA]
OUTPUT SCHEMA
Return a JSON object with the following structure:
json{ "diff_summary": "One-sentence summary of what changed", "changes": [ { "field_path": "dot.notation.path.to.changed.field", "change_type": "added | removed | modified | confirmed | retracted", "previous_value": null, "current_value": null, "trigger_evidence": "Specific span from the user utterance that caused this change", "rationale": "Explanation of why the system made this change", "confidence": "high | medium | low" } ], "unchanged_fields": ["list of field paths that were expected to change but did not"], "anomalies": [ { "type": "unexpected_change | missing_expected_change | contradiction | hallucination_risk", "field_path": "dot.notation.path", "description": "What looks wrong and why", "severity": "critical | warning | info" } ], "trigger_utterance_span": "The exact text from the user utterance most responsible for the state changes" }
CONSTRAINTS
- Only report changes that actually occurred between the two snapshots. Do not invent changes.
- For each change, cite the specific span from [USER_UTTERANCE] that triggered it.
- If a field was expected to change based on the utterance but did not, list it under
unchanged_fields. - Flag anomalies where the state change appears inconsistent with the utterance, the schema, or the previous state.
- Use
change_type: "confirmed"when a previously ambiguous or unverified field becomes confirmed. - Use
change_type: "retracted"when a previously set field is removed or marked invalid. - If no changes occurred, return an empty
changesarray and explain why indiff_summary. - Do not include fields that are identical between the two snapshots unless they appear in
unchanged_fields. - Maintain valid JSON syntax. Escape any internal quotes.
EXAMPLES
[EXAMPLES]
RISK LEVEL
[RISK_LEVEL]
To adapt this template, replace the square-bracket placeholders with your actual data. [PREVIOUS_STATE] and [CURRENT_STATE] should be serialized JSON objects representing your dialogue state at two consecutive turns. [USER_UTTERANCE] is the raw text of the user message that occurred between those state snapshots. [STATE_SCHEMA] is optional but strongly recommended—it helps the model interpret field semantics and detect anomalies. [EXAMPLES] should contain 1-3 few-shot examples of correct diffs for your specific state schema. [RISK_LEVEL] should be set to "high" for compliance or audit use cases, which will cause the model to be more conservative in its change detection and more thorough in its anomaly flagging. For debugging use cases, set it to "medium" to balance thoroughness with noise reduction.
Prompt Variables
Required inputs for the Dialogue State Diff Generation Prompt. Each placeholder must be populated before the prompt is assembled. Validation notes describe how to verify the input is well-formed before sending it to the model.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[PREVIOUS_STATE] | The dialogue state snapshot before the latest user turn. Must be a valid JSON object matching the application's state schema. | {"intent": "check_balance", "slots": {"account_type": "checking"}, "pending_actions": []} | Schema validation required. Must parse as valid JSON. Must conform to the expected state schema. Reject if missing required top-level keys or if field types are incorrect. |
[CURRENT_STATE] | The dialogue state snapshot after processing the latest user turn. Must be a valid JSON object matching the same schema as [PREVIOUS_STATE]. | {"intent": "check_balance", "slots": {"account_type": "savings"}, "pending_actions": ["confirm_account_change"]} | Schema validation required. Must parse as valid JSON. Must conform to the same schema as [PREVIOUS_STATE]. Structural drift between the two states should be flagged before diff generation. |
[USER_UTTERANCE] | The exact text of the user turn that triggered the state transition from [PREVIOUS_STATE] to [CURRENT_STATE]. | Actually, I meant my savings account, not checking. | Must be a non-empty string. Should be the raw user input without any preprocessing or truncation. If the turn was a tool result or system event, use [TRIGGER_EVENT] instead and set this to null. |
[TRIGGER_EVENT] | An alternative to [USER_UTTERANCE] for non-user triggers such as tool results, timeouts, or system events that caused the state change. | tool_result: get_accounts returned 2 accounts | Must be a non-empty string if [USER_UTTERANCE] is null. Should describe the event type and relevant payload. Reject if both [USER_UTTERANCE] and [TRIGGER_EVENT] are null or both are populated. |
[STATE_SCHEMA] | The JSON schema or type definition that both [PREVIOUS_STATE] and [CURRENT_STATE] must conform to. Used to validate inputs and to constrain the diff output. | {"type": "object", "properties": {"intent": {"type": "string"}, "slots": {"type": "object"}, "pending_actions": {"type": "array"}}, "required": ["intent", "slots"]} | Must be a valid JSON Schema or equivalent type definition. Schema validation of both state snapshots against this definition must pass before the prompt is assembled. Reject if schema is missing or malformed. |
[DIFF_OUTPUT_SCHEMA] | The expected output format for the diff. Specifies the structure the model must return, including fields for changed paths, old values, new values, change reason, and triggering evidence. | {"changes": [{"path": "slots.account_type", "old_value": "checking", "new_value": "savings", "reason": "user_correction", "evidence_span": "savings account"}]} | Must be a valid JSON Schema or type definition. The model output will be validated against this schema. Include required fields: path, old_value, new_value, reason, and evidence_span. Reject if schema is missing required fields. |
[CHANGE_REASON_TAXONOMY] | An enumerated list of valid change reasons the model can assign to each diff entry. Constrains the model to a controlled vocabulary for downstream processing. | ["user_correction", "new_information", "slot_filled", "slot_cleared", "intent_change", "action_added", "action_completed", "system_update"] | Must be a non-empty array of strings. Each reason must be a valid enum value. The model output must only use reasons from this list. Reject if taxonomy is empty or contains duplicates. |
[SESSION_ID] | A unique identifier for the conversation session. Used for traceability and audit log correlation. Not used in the diff logic itself but included in the output for record-keeping. | "sess_8a7b3c2d-4e5f-6a7b-8c9d-0e1f2a3b4c5d" | Must be a non-empty string. Should be a UUID or equivalent unique identifier. Validate format against the application's session ID convention. Reject if null or empty. |
Implementation Harness Notes
How to wire the Dialogue State Diff Generation Prompt into a production audit, debugging, or compliance pipeline.
This prompt is designed to operate as a deterministic, post-hoc analysis step, not a real-time user-facing feature. It should be triggered after a state management system commits a new dialogue state snapshot. The harness must provide the prompt with two consecutive, timestamped state snapshots and the exact user utterance that occurred between them. The primary consumers are developer debugging tools, compliance audit trails, and automated regression test suites that need to verify state transitions are correct and explainable.
The implementation should wrap the LLM call in a strict validation layer. Before the diff is stored or displayed, validate that the output JSON conforms to the expected schema: a change_type field from a controlled vocabulary (added, modified, deleted, confirmed, corrected), a trigger_utterance field that matches the provided user input, and a rationale string. Reject any output that references slots or entities not present in either the previous_state or current_state inputs. For high-compliance use cases, log the raw prompt, the model response, and the validation result to an append-only audit store before the diff is surfaced to any UI.
Model choice matters for cost and latency, not just quality. Since this is an offline, batch-compatible task, prefer a smaller, cheaper, and faster model (e.g., a fine-tuned lightweight model or a fast inference endpoint) if your state schema is stable. Run a calibration suite weekly: feed the prompt a set of 50-100 hand-labeled state transitions and measure exact-match accuracy on the change_type field and semantic similarity of the rationale against a reference. If accuracy drops below a threshold (e.g., 95%), escalate to a stronger model or trigger a prompt review. Avoid running this on every turn in a high-throughput chat product without sampling; instead, run it on a percentage of traffic for monitoring or on-demand for specific sessions under review.
Expected Output Contract
Validation rules for the dialogue state diff object. Use this contract to build parser checks, schema validators, and retry conditions before the diff is committed to an audit log or displayed to a developer.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
diff_id | string (UUID v4) | Must match UUID v4 regex; reject if missing or malformed | |
timestamp | string (ISO 8601 UTC) | Must parse as valid ISO 8601; must be within 5 minutes of system clock | |
previous_state_snapshot_id | string (UUID v4) | Must match the ID of the prior state snapshot; reject if null or mismatched | |
trigger_utterance_index | integer >= 0 | Must be a non-negative integer referencing a turn index present in the conversation history; reject if out of range | |
changes | array of change objects | Must be a non-empty array; each element must conform to the change object schema below | |
change.path | string (JSONPath) | Must be a valid JSONPath expression pointing to the modified field in the state schema; reject if path does not resolve | |
change.previous_value | any or null | Must be present; null allowed when the field was previously unset; type must match the target field's expected type | |
change.new_value | any or null | Must be present; null allowed when the field was removed; type must match the target field's expected type |
Common Failure Modes
Dialogue state diffs are brittle when the model hallucinates changes, misses the triggering utterance, or produces diffs that can't be applied. These cards cover the most common production failure modes and how to guard against them before shipping.
Hallucinated State Changes
What to watch: The model invents a state change that never occurred, adding or modifying slots without any supporting evidence in the conversation. This is the most dangerous failure mode because downstream systems trust the diff and act on fabricated data. Guardrail: Require the model to cite the exact user utterance span that triggered each change. Add a validator that rejects any diff entry lacking a source citation, and log all uncited changes for human review before they reach production state stores.
Missing Triggering Utterance
What to watch: A legitimate state change occurs in the conversation, but the diff omits it entirely. This silent failure causes state drift between the tracked state and the actual conversation, compounding over multiple turns. Guardrail: Run a reverse validation step that asks the model to reconstruct the expected new state from the diff and compare it against a separately extracted full state. Flag any slots present in the full state but absent from the diff for re-examination.
Incorrect Change Attribution
What to watch: The diff correctly identifies a change but attributes it to the wrong user turn, especially in multi-turn exchanges where the user corrected themselves or refined a value across several messages. Guardrail: Include turn indices in both state snapshots and require the diff to reference the specific turn index. Validate that the cited turn actually contains the claimed change. If multiple turns could be the source, flag for ambiguity rather than guessing.
Schema Drift in Diff Output
What to watch: The diff output format changes subtly across calls—fields renamed, nested structures flattened, or optional fields inconsistently included. This breaks downstream consumers that expect a stable diff schema. Guardrail: Enforce a strict JSON schema for the diff output with required fields and no additional properties allowed. Add a post-generation schema validator that rejects any diff that doesn't conform, and trigger a retry with the schema error included in the retry prompt.
Overly Granular Noise Diffs
What to watch: The model produces diffs for trivial or cosmetic changes—whitespace normalization, casing differences, or rephrasing that doesn't change semantic meaning. This floods audit logs and makes genuine changes harder to spot. Guardrail: Add a semantic equivalence check before emitting a diff entry. If the old and new values are semantically identical (e.g., 'yes' vs 'Yes'), suppress the diff entry. Include explicit instructions in the prompt to ignore formatting-only changes.
Context Window Truncation Artifacts
What to watch: When conversation history is long, the model may receive truncated or summarized prior state rather than the full snapshot. This causes false-positive diffs where the model 'detects' a change that only exists because it didn't see the original value. Guardrail: Always pass the complete prior state snapshot, not a summary. If context budget requires truncation, include a state_completeness flag in the prompt and instruct the model to output unknown for any change it cannot verify against complete prior state. Log truncation events separately.
Evaluation Rubric
Use this rubric to test the dialogue state diff prompt before integrating it into a compliance trace or debugging harness. Each criterion targets a specific failure mode observed in production diff generation.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Change Attribution Accuracy | Every state change is attributed to the correct user utterance span from [TURN_HISTORY] | Diff cites an assistant turn or a hallucinated user utterance as the trigger | Provide a labeled conversation pair where the ground-truth trigger is known; assert the diff's trigger_utterance_id matches the expected turn index |
Schema Compliance | Output strictly conforms to the [OUTPUT_SCHEMA] with all required fields present and no extra keys | Missing required fields, extra undocumented keys, or fields with incorrect types | Validate the raw output against the JSON Schema definition; reject on any schema violation before content evaluation |
No Hallucinated Changes | The diff contains zero state changes not present in the delta between [PREVIOUS_STATE] and [CURRENT_STATE] | Diff reports a slot change, intent shift, or action update that does not exist in the actual state delta | Compute the ground-truth diff programmatically from the two state snapshots; assert the generated diff is a strict subset of the true delta |
Change Rationale Quality | Every change includes a non-empty, specific rationale that references observable evidence from the user utterance | Rationale is empty, generic ('user provided new information'), or circular ('state changed because state changed') | Sample 20 diffs; have a reviewer check that each rationale cites a specific phrase or intent from the triggering utterance |
Omission Detection | All actual state changes between [PREVIOUS_STATE] and [CURRENT_STATE] are present in the diff | A slot was added, removed, or modified in the state but the diff omits it entirely | Compare the set of changed keys in the ground-truth delta against the set of changes in the diff; flag any missing entries |
Machine-Readable Diff Format | The diff includes a structured change list with before/after values, change type, and target field path | Diff is prose-only with no structured change records, or structured records are missing before/after values | Parse the diff output and assert that each change entry contains change_type, field_path, old_value, and new_value fields |
Idempotency Under Retry | Running the diff prompt twice on the same input pair produces semantically identical diffs | Second run produces different change counts, different trigger attributions, or reordered rationales | Execute the prompt three times on the same input; assert the set of change field_paths and trigger_utterance_ids is identical across runs |
Empty Diff Handling | When [PREVIOUS_STATE] and [CURRENT_STATE] are identical, the diff reports zero changes with a clear 'no changes detected' status | Diff fabricates a change, reports a non-zero change count, or omits the empty status indicator | Provide two identical state snapshots; assert change_count is 0 and status indicates no changes |
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
Add strict JSON schema validation for the diff output. Include a dedicated change_type enum (added, removed, modified, unchanged). Require confidence scores per field change. Add a system_triggered flag for state changes initiated by the assistant rather than the user. Wire in retry logic: if the diff fails schema validation, re-prompt with the validation error included.
codeYou are a dialogue state auditor producing machine-readable diffs. Input: - previous_state: [PREVIOUS_STATE_JSON] - current_state: [CURRENT_STATE_JSON] - trigger_utterance: [USER_UTTERANCE] - turn_metadata: [TURN_METADATA] Output strict JSON: { "diff_id": "string", "timestamp": "ISO8601", "changes": [ { "field_path": "$.slots.email.value", "change_type": "modified", "old_value": "string|null", "new_value": "string|null", "reason": "string", "trigger_span": "exact text from utterance", "confidence": 0.0-1.0, "system_triggered": false } ], "unchanged_critical_fields": ["field_paths that should have changed but didn't"], "validation_warnings": ["any consistency issues detected"] }
Watch for
- Silent format drift where the model drops required fields under high load
- Missing
trigger_spanwhen the user utterance is long or multi-intent - False positives on
unchanged_critical_fieldswhen the change was intentional - Confidence scores that are always 1.0 even for ambiguous changes

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