This prompt is for developers who have already designed a dialogue state machine and need the model to act as a deterministic transition function, not a conversational planner. The job-to-be-done is reliable, auditable conversation routing: given a current state (e.g., collecting_email), a map of valid transitions (e.g., collecting_email → verifying_email or collecting_email → clarification_needed), and the latest user utterance, the prompt must output the next state and the specific trigger condition that caused the transition. The ideal user is an engineering team building a task-oriented assistant, copilot, or support bot where the conversation flow must be predictable, testable, and explainable to business stakeholders or compliance reviewers.
Prompt
Dialogue State Machine Transition Prompt

When to Use This Prompt
Determines the next valid state in a predefined dialogue flow based on the current state, allowed transitions, and the latest user input.
Do not use this prompt for open-ended chat, assistants that dynamically plan their own conversation flow, or systems where the state graph is unknown at inference time. It assumes you have already defined your state machine externally—this prompt only evaluates transitions, it does not invent new states or re-route the conversation creatively. If your use case requires the model to propose new states, adapt the graph on the fly, or handle completely unanticipated user intents, you need a different architecture, likely combining intent classification with a planner prompt. This prompt also assumes single-turn transition evaluation; multi-step lookahead or probabilistic path scoring should be handled in application code, not in the prompt.
Before deploying, ensure your state machine definition is complete and unambiguous. Missing transitions will cause the model to either hallucinate a state or default to a fallback, both of which break determinism. Wire this prompt behind a validation layer that rejects any output state not present in your allowed transition map. For high-stakes domains like healthcare intake or financial transactions, add a human review step for any transition that changes a compliance-relevant state. Start by testing against a golden set of conversation turns with known correct transitions, and measure exact-match accuracy on the next state field—partial matches are not acceptable for a state machine.
Use Case Fit
Where the Dialogue State Machine Transition Prompt works and where it introduces risk. Use these cards to decide if this prompt fits your architecture before wiring it into production.
Good Fit: Explicit Workflows
Use when: your assistant follows a defined dialogue flow with known states (e.g., onboarding, troubleshooting, checkout). The prompt reliably maps current state + user input to the next valid state. Guardrail: define the full state machine schema in the prompt, including terminal states and fallback transitions.
Bad Fit: Open-Ended Chat
Avoid when: the conversation has no predefined state graph or users expect free-form exploration. The prompt will force-fit inputs into states, producing confusing transitions. Guardrail: use intent classification or dialogue act tagging instead; reserve state machines for structured workflows.
Required Input: State Schema
Risk: without an explicit state machine definition, the model hallucinates states and transitions. Guardrail: provide a complete JSON schema of valid states, allowed transitions per state, and trigger condition descriptions. Validate the output against this schema before committing the state change.
Operational Risk: State Drift
Risk: over multiple turns, the model's internal state representation can drift from the externally stored state, causing contradictory transitions. Guardrail: always pass the authoritative current state as input; never rely on the model remembering prior states from conversation history alone.
Operational Risk: Ambiguous Triggers
Risk: user inputs that partially match multiple transition conditions cause nondeterministic state selection. Guardrail: include a confidence score in the output schema and require human review or a clarification turn when confidence falls below a defined threshold.
Bad Fit: High-Stakes Autonomy
Avoid when: the state transition triggers an irreversible action (payment, deletion, legal submission) without human approval. Guardrail: separate state determination from action execution; use this prompt only to propose the next state, then route through an approval gate before acting.
Copy-Ready Prompt Template
A ready-to-adapt prompt template for determining the next dialogue state from a state machine definition, current state, and user input.
The prompt below is designed to be copied directly into your prompt management system, IDE, or orchestration layer. It accepts a formal state machine definition, the current active state, and the latest user input, then returns the next state and the trigger condition that caused the transition. Replace every square-bracket placeholder with your application's concrete values before sending the prompt to the model. The template includes guardrail instructions that prevent the model from inventing states not present in your definition and from applying transitions that violate your declared rules.
textYou are a dialogue state machine transition engine. Your only job is to determine the next state given a state machine definition, the current state, and the latest user input. ## STATE MACHINE DEFINITION Below is the complete set of valid states and allowed transitions. You must not invent states or transitions outside this definition. [STATE_MACHINE_DEFINITION] ## CURRENT STATE The system is currently in this state: [CURRENT_STATE] ## CONVERSATION HISTORY Recent turns for context. Use only to resolve references and understand user intent. Do not re-evaluate past transitions. [CONVERSATION_HISTORY] ## LATEST USER INPUT The user just said: [USER_INPUT] ## OUTPUT SCHEMA Return a single JSON object with exactly these fields: { "next_state": "string (must match a state name from the state machine definition)", "trigger_condition": "string (the specific condition or user intent that caused this transition, referencing the transition rules in the definition)", "confidence": "low | medium | high", "rationale": "string (brief explanation of why this transition was selected, citing evidence from the user input)", "requires_clarification": true | false, "clarification_question": "string | null (if requires_clarification is true, a precise question to ask the user to disambiguate)" } ## CONSTRAINTS 1. The next_state value must exactly match a state name listed in the state machine definition. Do not paraphrase, abbreviate, or invent state names. 2. Only apply transitions that are explicitly defined in the state machine definition. If no defined transition matches, set next_state to the current state and set requires_clarification to true. 3. If the user input is ambiguous and could trigger multiple valid transitions, set requires_clarification to true and explain which transitions are in conflict. 4. If the user input does not relate to any defined transition, keep the current state and set confidence to high with a rationale explaining no transition applies. 5. Do not hallucinate user intent. Base the trigger_condition only on explicit evidence in the user input and conversation history. 6. If [RISK_LEVEL] is "high", set confidence to "low" for any transition that modifies account data, payment information, or personally identifiable information, and set requires_clarification to true. ## EXAMPLES [FEW_SHOT_EXAMPLES]
Adaptation notes: Replace [STATE_MACHINE_DEFINITION] with a structured description of your states and transitions—ideally a JSON object or a bulleted list of state -> [valid_next_states] mappings with trigger descriptions. Replace [CURRENT_STATE] with the state your application has persisted from the previous turn. Replace [CONVERSATION_HISTORY] with the last N turns, formatted consistently. Replace [USER_INPUT] with the raw user message. Replace [RISK_LEVEL] with "low", "medium", or "high" depending on the domain. Replace [FEW_SHOT_EXAMPLES] with 2–4 annotated examples showing correct transitions, including at least one ambiguous case that triggers clarification and one no-op case where the state should not change. If your state machine is large, consider moving the definition into a retrieved context block or a tool description rather than inlining it every turn.
Before integrating this prompt into production, run it against a golden test set of at least 20 turns covering every defined transition, at least 3 out-of-scope inputs, and 2 ambiguous inputs. Measure exact-match accuracy on next_state and requires_clarification. For high-risk domains, add a human review step when confidence is "low" or when requires_clarification is true and the clarification question will be shown to the user. Log every transition decision with the full prompt, model response, and validator output so you can debug state drift in production.
Prompt Variables
Inputs the prompt needs to work reliably. Validate each before sending to prevent hallucinated states and invalid transitions.
| Placeholder | Purpose | Example | Validation Notes |
|---|---|---|---|
[CURRENT_STATE] | The active dialogue state before processing the latest user turn | {"state": "collecting_shipping_address", "slots": {"street": null, "city": "Austin"}} | Must be a valid JSON object matching the state schema. Reject if null or if state name is not in [VALID_STATES]. |
[VALID_TRANSITIONS] | The set of allowed next states from the current state, with trigger conditions | [{"from": "collecting_shipping_address", "to": "collecting_payment", "trigger": "all_required_slots_filled"}] | Must be a non-empty JSON array. Each entry must have from, to, and trigger fields. Reject if from does not match [CURRENT_STATE]. |
[USER_INPUT] | The latest user utterance to evaluate for state transition | Yes, please use 123 Main Street, Austin TX 78701 | Must be a non-empty string. Trim whitespace. Reject if only punctuation or whitespace. Null not allowed. |
[CONVERSATION_HISTORY] | Prior turns for context when transition depends on multi-turn patterns | [{"role": "assistant", "content": "What is your shipping address?"}, {"role": "user", "content": "Austin"}] | Must be a JSON array of turn objects with role and content. May be empty array for first turn. Validate role values are user or assistant only. |
[STATE_SCHEMA] | The full state machine definition including all valid states, slots, and transition rules | {"states": ["greeting", "collecting_shipping_address", "collecting_payment", "confirming_order"], "transitions": [...]} | Must be a valid JSON object with states array and transitions array. Reject if states array is empty or contains duplicates. Validate all transition references point to defined states. |
[OUTPUT_SCHEMA] | The required JSON structure for the transition output | {"next_state": "string", "trigger": "string", "confidence": "float", "evidence": "string"} | Must be a valid JSON Schema or example structure. Reject if missing required fields next_state and trigger. Confidence must be a float between 0.0 and 1.0. |
[GUARDRAILS] | Rules that block invalid transitions or hallucinated states | ["next_state must exist in VALID_TRANSITIONS.to", "reject transition if confidence < 0.7", "require evidence span from USER_INPUT"] | Must be a non-empty JSON array of rule strings. Each rule must be parseable as a boolean check. Reject if guardrails array is empty for production use. |
[FALLBACK_STATE] | The state to return when no valid transition is detected or confidence is below threshold | {"next_state": "clarifying_intent", "trigger": "low_confidence_fallback", "confidence": 0.0} | Must be a valid state object matching [OUTPUT_SCHEMA]. State name must exist in [STATE_SCHEMA].states. Trigger must indicate fallback reason. |
Implementation Harness Notes
How to wire the Dialogue State Machine Transition Prompt into an application or agent workflow.
This prompt is not a standalone chatbot. It is a deterministic state transition function that should be called after every user turn, before the assistant generates a response. The application owns the canonical state machine definition—the prompt only evaluates the next transition. Store the current state in your application's session object (e.g., session.state = 'collecting_symptoms'). After the user sends input, call the LLM with this prompt, passing the current state, the full list of valid transitions defined in your state machine config, and the raw user text. The prompt returns a JSON object with next_state and trigger_condition. Your application then validates that the returned next_state exists in your state machine definition before updating session.state.
Validation and Guardrails: Never trust the model's output directly. Implement a hard validation layer in your application code that rejects any next_state not present in your predefined [VALID_TRANSITIONS] list. If validation fails, log the invalid transition attempt, fall back to the current state, and optionally inject a clarification prompt asking the user to rephrase. For high-stakes domains (healthcare, finance, legal), add a human review queue for any transition that the model flags with low confidence or that crosses a risk boundary (e.g., moving from 'information_gathering' to 'recommendation'). The prompt includes a [RISK_LEVEL] parameter—use it to gate whether transitions require confirmation. Retry logic: If the model returns malformed JSON or a state outside the valid set, retry once with a stricter prompt that includes the validation error message. If the second attempt fails, freeze the state and escalate.
Integration pattern: Wire this as a synchronous pre-processing step in your turn pipeline: User Input → State Transition Prompt → Validate Transition → Update Session State → Generate Assistant Response. The updated state then feeds into your response-generation prompt as part of [CONTEXT]. Logging: Log every transition attempt—input state, user utterance, model-returned state, validation result, and final committed state. This audit trail is essential for debugging state machine drift and for compliance use cases. Model choice: Use a fast, instruction-following model (e.g., GPT-4o-mini, Claude Haiku) for this step since it runs on every turn. Reserve larger models for the response-generation step. Avoid: Do not use this prompt to generate user-facing text. Do not let the model invent new states. Do not skip validation even if the output looks correct.
Expected Output Contract
Fields, data types, and validation rules for the dialogue state machine transition response. Use this contract to parse and validate the model output before committing the state change.
| Field or Element | Type or Format | Required | Validation Rule |
|---|---|---|---|
next_state | string | Must exactly match one of the valid state names provided in [VALID_STATES]. Reject if not in the allowed set. | |
trigger_utterance_index | integer | Must be a valid index into the [CONVERSATION_HISTORY] array. Reject if index is out of bounds or negative. | |
trigger_condition | string | Must be a non-empty string that maps to one of the defined transition conditions in [TRANSITION_RULES]. Reject if condition is not recognized. | |
confidence | number | Must be a float between 0.0 and 1.0 inclusive. Reject if outside range. If confidence < [MIN_CONFIDENCE_THRESHOLD], route to human review. | |
state_change_summary | string | Must be a non-empty string of 10-300 characters summarizing why the transition occurred. Reject if empty or exceeds length limit. | |
guardrail_violations | array of strings | If present, each element must match a guardrail ID from [GUARDRAIL_DEFINITIONS]. If any violation is present, block the state transition and escalate. | |
requires_clarification | boolean | Must be true or false. If true, the transition should be held pending a clarification turn. Reject if not a strict boolean. | |
clarification_question | string | Required if requires_clarification is true. Must be a non-empty question string. Reject if requires_clarification is true and this field is missing or empty. |
Common Failure Modes
What breaks first when using a state machine transition prompt in production and how to guard against it.
Hallucinated States
What to watch: The model invents a state name that does not exist in the defined state machine schema, causing downstream routing or logic errors. This often happens when the user input is ambiguous or the conversation drifts. Guardrail: Post-process the output against a strict allowlist of valid states. If the returned state is not in the set, log the raw output, default to the current state, and trigger a clarification prompt.
Invalid Transition Jumps
What to watch: The model selects a next state that is not a valid transition from the current state, skipping required intermediate steps like confirmation or data collection. Guardrail: Validate the transition against an adjacency map of allowed transitions. On mismatch, reject the transition, append the valid options to the retry prompt, and re-invoke the model with explicit constraints.
Context Window Truncation
What to watch: In long conversations, the initial state definition or transition rules are pushed out of the context window, causing the model to forget the valid schema and guess. Guardrail: Always inject the current state and a compact list of valid next states at the top of the prompt. Use a sliding window that preserves the state definition as a pinned system message.
Stale State Drift
What to watch: The model fails to update the state when a user corrects earlier information or changes their goal mid-flow, causing the state machine to proceed based on outdated facts. Guardrail: Include a pre-processing step that detects corrections or topic shifts. If detected, re-evaluate the current state before running the transition prompt, potentially rolling back to an earlier state.
Ambiguous Trigger Classification
What to watch: The user input matches multiple transition triggers weakly, causing the model to oscillate between states or pick a low-confidence transition that breaks the flow. Guardrail: Require the model to output a confidence score for the transition. If confidence is below a threshold, route to a clarification state that asks the user to disambiguate rather than guessing.
Silent State Desynchronization
What to watch: The application's external state store and the prompt's internal state representation diverge due to a parsing error or a missed update, leading to the assistant acting on a state the application has already left. Guardrail: After every transition, compare the model's output state with the application's canonical state. If they differ, log a desynchronization event and re-sync the prompt context with the authoritative application state before the next turn.
Evaluation Rubric
Run this rubric against a golden dataset of 50+ labeled dialogue examples before shipping. Each row checks a specific failure mode observed in state machine transition prompts.
| Criterion | Pass Standard | Failure Signal | Test Method |
|---|---|---|---|
Valid Transition Selection | Next state is in the set of valid transitions from [CURRENT_STATE] per the provided [STATE_MACHINE_DEFINITION] | Output state is not listed as a valid transition; hallucinated state name; transition to a state that does not exist in the definition | Schema check: assert output state exists in [STATE_MACHINE_DEFINITION].states and is present in [CURRENT_STATE].valid_transitions |
Trigger Condition Grounding | The [TRIGGER_CONDITION] field references a specific user utterance span or explicit slot value from [USER_INPUT] | Trigger condition is vague (e.g., 'user wants help'), references information not in the input, or copies the state name as the trigger | Span check: verify trigger text or slot reference appears in or is directly inferable from [USER_INPUT] without external knowledge |
Guardrail Rejection on Invalid Input | When [USER_INPUT] does not match any valid transition trigger, output next_state = null and trigger_condition = null | Model forces a transition to the closest-matching state; model invents a trigger; model defaults to a fallback state not defined in the guardrail rules | Adversarial test: send 10 inputs that match no valid trigger and assert null output; measure forced-transition rate |
State Schema Compliance | Output matches [OUTPUT_SCHEMA] exactly: required fields present, no extra fields, correct types | Missing required field; extra hallucinated field (e.g., 'confidence' when not in schema); string where boolean expected | JSON Schema validation: validate output against [OUTPUT_SCHEMA] using a standard JSON Schema validator; reject on additionalProperties |
No State Mutation Without Transition | When next_state equals [CURRENT_STATE], no state attributes are modified and trigger_condition explains why no transition occurred | Model changes state attributes (e.g., slot values, flags) while claiming no transition; trigger_condition is empty or says 'no change' without evidence | Diff test: when next_state == [CURRENT_STATE], assert all state attributes in output match [CURRENT_STATE] attributes exactly |
Multi-Intent Disambiguation | When [USER_INPUT] contains multiple intents that could trigger different transitions, output exactly one next_state with the highest-priority match per [PRIORITY_RULES] | Model outputs multiple states; model oscillates; model picks a low-priority transition ignoring [PRIORITY_RULES] | Labeled multi-intent test set: assert single next_state output; assert selected state matches priority-ordered ground truth |
Correction Handling | When [USER_INPUT] is a correction of a prior assistant action, transition to the correction state defined in [STATE_MACHINE_DEFINITION] and include the corrected value in trigger_condition | Model treats correction as a new intent; model ignores the correction and stays in current state; model accepts correction but does not record corrected value | Correction test cases: inject mid-dialogue corrections into golden set; verify transition to correction state and presence of corrected value in trigger_condition |
Empty or Noisy Input Handling | When [USER_INPUT] is empty, whitespace-only, or pure noise (e.g., 'asdf'), output next_state = null with trigger_condition = 'invalid_input' | Model hallucinates a transition from noise; model treats empty input as continuation; model errors or produces unparseable output | Noise injection test: send 20 empty/noise inputs across different [CURRENT_STATE] values; assert null transition rate >= 95% |
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 a simple JSON schema for states and transitions. Use a lightweight model call without strict validation to explore whether your state definitions capture real user flows. Replace the [STATE_DEFINITIONS] placeholder with a flat list of 3-5 states and 5-8 transitions. Skip the guardrail checks initially.
codeYou are a dialogue state tracker. Given the current state [CURRENT_STATE], the valid transitions [VALID_TRANSITIONS], and the user input [USER_INPUT], return the next state as JSON: {"next_state": "...", "trigger": "..."}
Watch for
- Hallucinated states not in your transition table
- Missing trigger explanations that make debugging impossible
- Overly broad transition conditions that fire on vague inputs
- No handling of the
stayorno_changecase

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