Repository Public
1---2title: Increase output consistency3url: https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/increase-consistency4description: Make Claude's outputs more consistent by specifying exact formats, prefilling responses, constraining with examples, and grounding answers in retrieval.5---67<Tip>8 **For guaranteed JSON schema conformance**910 If you need Claude to always output valid JSON that conforms to a specific schema, use [Structured Outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) instead of the prompt engineering techniques below. Structured outputs provide guaranteed schema compliance and are specifically designed for this use case.1112 The techniques below are useful for general output consistency or when you need flexibility beyond strict JSON schemas.13</Tip>1415Here's how to make Claude's responses more consistent:1617## Specify the desired output format1819Precisely define your desired output format using JSON, XML, or custom templates so that Claude follows every output formatting element you require.2021<Accordion title="Example: Standardizing customer feedback">22 ```text User wrap23 You're a Customer Insights AI. Analyze this feedback and output in JSON format with keys: "sentiment" (positive/negative/neutral), "key_issues" (list), and "action_items" (list of dicts with "team" and "task").2425 "I've been a loyal user for 3 years, but the recent UI update is a disaster. Finding basic features is now a scavenger hunt. Plus, the new 'premium' pricing is outrageous. I'm considering switching unless this is fixed ASAP."26 ```2728 ```json Assistant29 {30 "sentiment": "negative",31 "key_issues": [32 "Poor UI/UX in recent update",33 "Difficulty finding basic features",34 "Perceived high pricing (new 'premium' tier)"35 ],36 "action_items": [37 {38 "team": "Product",39 "task": "Conduct usability testing and iterate on UI based on findings"40 },41 {42 "team": "UX",43 "task": "Create a feature discovery guide or onboarding flow"44 },45 {46 "team": "Marketing",47 "task": "Review pricing strategy and communicate value proposition"48 },49 {50 "team": "Customer Success",51 "task": "Reach out to user, offer concessions to prevent churn"52 }53 ]54 }55 ```56</Accordion>5758## Prefill Claude's response5960<Note>61 Prefilling is not supported on Claude 4.6 and later models and 6263 [Claude Mythos Preview](https://anthropic.com/glasswing)6465 . Use 6667 [structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs)6869 on models that support it, or system prompt instructions, instead.70</Note>7172Prefill the `Assistant` turn with your desired format. This trick bypasses Claude's friendly preamble and enforces your structure.7374<Accordion title="Example: Daily sales report">75 ```text User wrap76 You're an insightful Sales Intelligence AI. Generate today's sales report.7778 Structure the report like this:7980 <report>81 <summary>82 <metric name="total_revenue">$0.00</metric>83 <metric name="units_sold">0</metric>84 <metric name="avg_order_value">$0.00</metric>85 </summary>86 <top_products>87 <product>88 <name>Product Name</name>89 <revenue>$0.00</revenue>90 <units>0</units>91 </product>92 ...93 </top_products>94 <regional_performance>95 <region>96 <name>Region Name</name>97 <revenue>$0.00</revenue>98 <growth>0.0%</growth>99 </region>100 ...101 </regional_performance>102 <action_items>103 <item>Action item.</item>104 ...105 </action_items>106 </report>107 ```108109 ```xml Assistant (prefill)110 <report>111 <summary>112 <metric name=113 ```114115 ```xml Assistant116 "total_revenue">$842,567.00</metric>117 <metric name="units_sold">15,238</metric>118 <metric name="avg_order_value">$55.29</metric>119 </summary>120 <top_products>121 <product>122 <name>AcmeGuard Pro</name>123 <revenue>$325,890.00</revenue>124 <units>3,621</units>125 </product>126 <product>127 <name>AcmeVault Enterprise</name>128 <revenue>$254,400.00</revenue>129 <units>1,272</units>130 </product>131 <product>132 <name>AcmeBoost XL</name>133 <revenue>$147,690.00</revenue>134 <units>4,923</units>135 </product>136 </top_products>137 <regional_performance>138 <region>139 <name>APAC</name>140 <revenue>$258,960.00</revenue>141 <growth>12.8%</growth>142 </region>143 <region>144 <name>EMEA</name>145 <revenue>$325,478.00</revenue>146 <growth>3.2%</growth>147 </region>148 <region>149 <name>Americas</name>150 <revenue>$258,129.00</revenue>151 <growth>-2.1%</growth>152 </region>153 </regional_performance>154 <action_items>155 <item>Investigate Americas revenue drop; schedule regional sales team meeting.</item>156 <item>Accelerate CloudGuard Pro rollout in APAC to capitalize on growth.</item>157 <item>Review NetBoost XL pricing; high volume but lower revenue.</item>158 </action_items>159 </report>160 ```161</Accordion>162163## Constrain with examples164165Provide examples of your desired output. This is more effective than abstract instructions.166167<Accordion title="Example: Generating consistent market intelligence">168 ```text User wrap169 As a Market Intelligence AI, your task is to analyze data about our competitors. Here is our competitor data:170 <data>171 {{DATA}}172 </data>173174 Output following this example format:175176 <competitor>177 <name>Rival Inc</name>178 <overview>A 50-word summary.</overview>179 <swot>180 <strengths>- Bullet points</strengths>181 <weaknesses>- Bullet points</weaknesses>182 <opportunities>- Bullet points</opportunities>183 <threats>- Bullet points</threats>184 </swot>185 <strategy>A 30-word strategic response.</strategy>186 </competitor>187188 Now, analyze AcmeGiant and AcmeDataCo using this format.189 ```190191 ```text Assistant wrap192 <competitor>193 <name>AcmeGiant</name>194 <overview>Global tech leader with a vast ecosystem of consumer and enterprise products. Known for innovation, strong brand, and deep customer lock-in through integrated hardware, software, and services.</overview>195 <swot>196 <strengths>197 - Massive R&D budget fuels continuous innovation198 - Loyal customer base and powerful brand recognition199 - Synergistic product ecosystem increases switching costs200 </strengths>201 <weaknesses>202 - High prices may deter cost-sensitive customers203 - Slow to address enterprise-specific customization needs204 - Privacy concerns and regulatory scrutiny in multiple markets205 </weaknesses>206 <opportunities>207 - Growing demand for AI and ML capabilities208 - Expansion into emerging markets209 - Acquisitions to fill product or talent gaps210 </opportunities>211 <threats>212 - Rapid rise of cloud-native competitors213 - Antitrust lawsuits and regulatory actions214 - Talent poaching by startups and competitors215 </threats>216 </swot>217 <strategy>Focus on our agility and customization. Target TechGiant's slow enterprise response and privacy issues in our marketing.</strategy>218 </competitor>219220 <competitor>221 <name>AcmeDataCo</name>222 <overview>Rising star in data analytics and visualization. Offers intuitive, self-service BI tools with a freemium model, appealing to startups and enterprise teams alike.</overview>223 <swot>224 <strengths>225 - User-friendly interface reduces need for specialized training226 - Freemium model lowers barrier to entry, drives viral growth227 - Strong product-market fit with rise of data-driven decisions228 </strengths>229 <weaknesses>230 - Limited advanced analytics compared to established BI tools231 - Scaling issues reported with very large datasets232 - Dependent on third-party cloud infrastructure (AWS)233 </weaknesses>234 <opportunities>235 - Expanding into predictive analytics and AI-driven insights236 - Forming strategic alliances with complementary tech vendors237 - Customizable dashboards for industry-specific solutions238 </opportunities>239 <threats>240 - Market saturation; many new entrants in self-service BI241 - Enterprise BI giants developing more user-friendly tools242 - Data privacy regulations increasing compliance complexity243 </threats>244 </swot>245 <strategy>Highlight our robust enterprise features and data governance. Target accounts struggling with DataCo's scale limitations.</strategy>246 </competitor>247 ```248</Accordion>249250## Use retrieval for contextual consistency251252For tasks requiring consistent context (for example, chatbots, knowledge bases), use retrieval to ground Claude's responses in a fixed information set.253254<Accordion title="Example: Enhancing IT support consistency">255 ```text User wrap256 You're our IT Support AI that draws on knowledge base data. Here are entries from your knowledge base:257258 <kb>259 <entry>260 <id>1</id>261 <title>Reset Active Directory password</title>262 <content>1. Go to password.ourcompany.com263 2. Enter your username264 3. Click "Forgot Password"265 4. Follow email instructions</content>266 </entry>267 <entry>268 <id>2</id>269 <title>Connect to VPN</title>270 <content>1. Install GlobalProtect from software center271 2. Open GlobalProtect, enter "vpn.ourcompany.com"272 3. Use AD credentials to log in</content>273 </entry>274 </kb>275276 When helping users, always check the knowledge base first. Respond in this format:277278 <response>279 <kb_entry>Knowledge base entry used</kb_entry>280 <answer>Your response</answer>281 </response> Write some test questions for yourself and answer them using the knowledge base, just to make sure you understand how to use the knowledge base properly.282 ```283284 ```text Assistant wrap285 Understood. I'll use the knowledge base for consistent responses. Let's test with a couple of scenarios.286287 User: Hey, I can't log into my email. I think I forgot my password.288289 <response>290 <kb_entry>1: Reset Active Directory password</kb_entry>291 <answer>I understand you're having trouble logging into your email due to a forgotten password. No worries, this is a common issue. To reset your Active Directory password, which is used for email access, follow these steps:292293 1. Go to password.ourcompany.com294 2. Enter your username (same as your email address)295 3. Click on the "Forgot Password" link296 4. You'll receive an email with instructions. Follow them to reset your password.297298 After resetting, you should be able to log into your email. Let me know if you need any further assistance.</answer>299 </response>300301 User: I'm working from home today. How do I access internal resources?302303 <response>304 <kb_entry>2: Connect to VPN</kb_entry>305 <answer>Great question! To access internal resources while working from home, you'll need to connect to our company VPN (Virtual Private Network). Here's how to set that up:306307 1. First, install the GlobalProtect VPN client. You can find this in our software center.308 2. Once installed, open the GlobalProtect application.309 3. In the server field, enter "vpn.ourcompany.com".310 4. Use your Active Directory (AD) credentials to log in - the same username and password you use for your email.311312 Once connected, you'll have secure access to all internal resources as if you were in the office. Let me know if you run into any issues during setup.</answer>313 </response>314 ```315</Accordion>316317## Chain prompts for complex tasks318319Break down complex tasks into smaller, consistent subtasks. Each subtask gets Claude's full attention, reducing inconsistency errors across scaled workflows.320321## Keep Claude in character322323For role-based applications, maintaining consistent character requires deliberate prompting.324325* **Use system prompts to set the role:** Use [system prompts](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/claude-prompting-best-practices#give-claude-a-role) to define Claude's role and personality. This sets a strong foundation for consistent responses.326 <Tip>327 When setting up the character, provide detailed information about the personality, background, and any specific traits or quirks. This helps the model better emulate and generalize the character's traits.328 </Tip>329* **Prepare Claude for possible scenarios:** Provide a list of common scenarios and expected responses in your prompts. This "trains" Claude to handle diverse situations without breaking character.330331<Accordion title="Example: Enterprise chatbot for role prompting">332 ```text System wrap333 You are AcmeBot, the enterprise-grade AI assistant for AcmeTechCo. Your role:334 - Analyze technical documents (TDDs, PRDs, RFCs)335 - Provide actionable insights for engineering, product, and ops teams336 - Maintain a professional, concise tone337 ```338339 ```text User wrap340 Here is the user query for you to respond to:341 <user_query>342 {{USER_QUERY}}343 </user_query>344345 Your rules for interaction are:346 - Always reference AcmeTechCo standards or industry best practices347 - If unsure, ask for clarification before proceeding348 - Never disclose confidential AcmeTechCo information.349350 As AcmeBot, you should handle situations along these guidelines:351 - If asked about AcmeTechCo IP: "I cannot disclose TechCo's proprietary information."352 - If questioned on best practices: "Per ISO/IEC 25010, we prioritize..."353 - If unclear on a doc: "To ensure accuracy, please clarify section 3.2..."354 ```355</Accordion>356