# Source: https://platform.claude.com/docs/en/test-and-evaluate/strengthen-guardrails/increase-consistency.md

# Increase output consistency

---

<Tip>
**For guaranteed JSON schema conformance**

If you need Claude to always output valid JSON that conforms to a specific schema, use [Structured Outputs](/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.

The techniques below are useful for general output consistency or when you need flexibility beyond strict JSON schemas.
</Tip>

Here's how to make Claude's responses more consistent:

## Specify the desired output format
Precisely define your desired output format using JSON, XML, or custom templates so that Claude understands every output formatting element you require.

<section title="Example: Standardizing customer feedback">

    | Role | Content |
    | ---- | ------- |
    | User | 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").<br/><br/>"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." |
    | Assistant | \{<br/>  "sentiment": "negative",<br/>  "key_issues": [<br/>    "Poor UI/UX in recent update",<br/>    "Difficulty finding basic features",<br/>    "Perceived high pricing (new 'premium' tier)"<br/>  ],<br/>  "action_items": [<br/>    \{<br/>      "team": "Product",<br/>      "task": "Conduct usability testing and iterate on UI based on findings"<br/>    \},<br/>    \{<br/>      "team": "UX",<br/>      "task": "Create a feature discovery guide or onboarding flow"<br/>    \},<br/>    \{<br/>      "team": "Marketing",<br/>      "task": "Review pricing strategy and communicate value proposition"<br/>    },<br/>    \{<br/>      "team": "Customer Success",<br/>      "task": "Reach out to user, offer concessions to prevent churn"<br/>    \}<br/>  ]<br/>\} |

</section>

## Prefill Claude's response
Prefill the `Assistant` turn with your desired format. This trick bypasses Claude's friendly preamble and enforces your structure.

<section title="Example: Daily sales report">

    | Role | Content |
    | ---- | ------- |
    | User | You're an insightful Sales Intelligence AI. Generate today's sales report.<br/><br/>Structure the report like this:<br/><br/>\<report><br/>    \<summary><br/>        \<metric name="total_revenue">\$0.00\</metric><br/>        \<metric name="units_sold">0\</metric><br/>        \<metric name="avg_order_value">\$0.00\</metric><br/>    \</summary><br/>    \<top_products><br/>        \<br/>            \<name>Product Name\</name><br/>            \<revenue>\$0.00\</revenue><br/>            \<units>0\</units><br/>        \</product><br/>        ...<br/>    \</top_products><br/>    \<regional_performance><br/>        \<region><br/>            \<name>Region Name\</name><br/>            \<revenue>\$0.00\</revenue><br/>            \<growth>0.0%\</growth><br/>        \</region><br/>        ...<br/>    \</regional_performance><br/>    \<action_items><br/>        \<item>Action item.\</item><br/>        ...<br/>    \</action_items><br/>\</report> |
    | Assistant (prefill) | \<report><br/>    \<summary><br/>        \<metric name= |
    | Assistant | "total_revenue">\$842,567.00\</metric><br/>        \<metric name="units_sold">15,238\</metric><br/>        \<metric name="avg_order_value">\$55.29\</metric><br/>    \</summary><br/>    \<top_products><br/>        \<br/>            \<name>AcmeGuard Pro\</name><br/>            \<revenue>\$325,890.00\</revenue><br/>            \<units>3,621\</units><br/>        \</product><br/>        \<br/>            \<name>AcmeVault Enterprise\</name><br/>            \<revenue>\$254,400.00\</revenue><br/>            \<units>1,272\</units><br/>        \</product><br/>        \<br/>            \<name>AcmeBoost XL\</name><br/>            \<revenue>\$147,690.00\</revenue><br/>            \<units>4,923\</units><br/>        \</product><br/>    \</top_products><br/>    \<regional_performance><br/>        \<region><br/>            \<name>APAC\</name><br/>            \<revenue>\$258,960.00\</revenue><br/>            \<growth>12.8%\</growth><br/>        \</region><br/>        \<region><br/>            \<name>EMEA\</name><br/>            \<revenue>\$325,478.00\</revenue><br/>            \<growth>3.2%\</growth><br/>        \</region><br/>        \<region><br/>            \<name>Americas\</name><br/>            \<revenue>\$258,129.00\</revenue><br/>            \<growth>-2.1%\</growth><br/>        \</region><br/>    \</regional_performance><br/>    \<action_items><br/>        \<item>Investigate Americas revenue drop; schedule regional sales team meeting.\</item><br/>        \<item>Accelerate CloudGuard Pro rollout in APAC to capitalize on growth.\</item><br/>        \<item>Review NetBoost XL pricing; high volume but lower revenue.\</item><br/>    \</action_items><br/>\</report> |

</section>

## Constrain with examples
Provide examples of your desired output. This trains Claude's understanding better than abstract instructions.

<section title="Example: Generating consistent market intelligence">

    | Role | Content |
    | ---- | ------- |
    | User | As a Market Intelligence AI, your task is to analyze data about our competitors. Here is our competitor data:<br/>\<data><br/>\{\{DATA}}<br/>\</data><br/><br/>Output following this example format:<br/><br/>\<competitor><br/>  \<name>Rival Inc\</name><br/>  \<overview>A 50-word summary.\</overview><br/>  \<swot><br/>    \<strengths>- Bullet points\</strengths><br/>    \<weaknesses>- Bullet points\</weaknesses><br/>    \<opportunities>- Bullet points\</opportunities><br/>    \<threats>- Bullet points\</threats><br/>  \</swot><br/>  \<strategy>A 30-word strategic response.\</strategy><br/>\</competitor><br/><br/>Now, analyze AcmeGiant and AcmeDataCo using this format. |
    | Assistant | \<competitor><br/>  \<name>AcmeGiant\</name><br/>  \<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><br/>  \<swot><br/>    \<strengths><br/>      - Massive R\&D budget fuels continuous innovation<br/>      - Loyal customer base and powerful brand recognition<br/>      - Synergistic product ecosystem increases switching costs<br/>    \</strengths><br/>    \<weaknesses><br/>      - High prices may deter cost-sensitive customers<br/>      - Slow to address enterprise-specific customization needs<br/>      - Privacy concerns and regulatory scrutiny in multiple markets<br/>    \</weaknesses><br/>    \<opportunities><br/>      - Growing demand for AI and ML capabilities<br/>      - Expansion into emerging markets<br/>      - Acquisitions to fill product or talent gaps<br/>    \</opportunities><br/>    \<threats><br/>      - Rapid rise of cloud-native competitors<br/>      - Antitrust lawsuits and regulatory actions<br/>      - Talent poaching by startups and competitors<br/>    \</threats><br/>  \</swot><br/>  \<strategy>Focus on our agility and customization. Target TechGiant's slow enterprise response and privacy issues in our marketing.\</strategy><br/>\</competitor><br/><br/>\<competitor><br/>  \<name>AcmeDataCo\</name><br/>  \<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><br/>  \<swot><br/>    \<strengths><br/>      - User-friendly interface reduces need for specialized training<br/>      - Freemium model lowers barrier to entry, drives viral growth<br/>      - Strong product-market fit with rise of data-driven decisions<br/>    \</strengths><br/>    \<weaknesses><br/>      - Limited advanced analytics compared to established BI tools<br/>      - Scaling issues reported with very large datasets<br/>      - Dependent on third-party cloud infrastructure (AWS)<br/>    \</weaknesses><br/>    \<opportunities><br/>      - Expanding into predictive analytics and AI-driven insights<br/>      - Forming strategic alliances with complementary tech vendors<br/>      - Customizable dashboards for industry-specific solutions<br/>    \</opportunities><br/>    \<threats><br/>      - Market saturation; many new entrants in self-service BI<br/>      - Enterprise BI giants developing more user-friendly tools<br/>      - Data privacy regulations increasing compliance complexity<br/>    \</threats><br/>  \</swot><br/>  \<strategy>Highlight our robust enterprise features and data governance. Target accounts struggling with DataCo's scale limitations.\</strategy><br/>\</competitor> |

</section>

## Use retrieval for contextual consistency
For tasks requiring consistent context (e.g., chatbots, knowledge bases), use retrieval to ground Claude's responses in a fixed information set.

<section title="Example: Enhancing IT support consistency">

    | Role | Content |
    | ---- | ------- |
    | User | You're our IT Support AI that draws on knowledge base data. Here are entries from your knowledge base:<br/><br/>\<kb><br/>  \<entry><br/>    \<id>1\</id><br/>    \<title>Reset Active Directory password\</title><br/>    \<content>1. Go to password.ourcompany.com<br/>2. Enter your username<br/>3. Click "Forgot Password"<br/>4. Follow email instructions\</content><br/>  \</entry><br/>  \<entry><br/>    \<id>2\</id><br/>    \<title>Connect to VPN\</title><br/>    \<content>1. Install GlobalProtect from software center<br/>2. Open GlobalProtect, enter "vpn.ourcompany.com"<br/>3. Use AD credentials to log in\</content><br/>  \</entry><br/>\</kb><br/><br/>When helping users, always check the knowledge base first. Respond in this format:<br/><br/>\<response><br/>  \<kb_entry>Knowledge base entry used\</kb_entry><br/>  \<answer>Your response\</answer><br/>\</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. |
    | Assistant | Understood. I'll use the knowledge base for consistent responses. Let's test with a couple of scenarios.<br/><br/>User: Hey, I can't log into my email. I think I forgot my password.<br/><br/>\<response><br/>  \<kb_entry>1: Reset Active Directory password\</entry><br/>  \<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:<br/><br/>1. Go to password.ourcompany.com<br/>2. Enter your username (same as your email address)<br/>3. Click on the "Forgot Password" link<br/>4. You'll receive an email with instructions. Follow them to reset your password.<br/><br/>After resetting, you should be able to log into your email. Let me know if you need any further assistance.\</answer><br/>\</response><br/><br/>User: I'm working from home today. How do I access internal resources?<br/><br/>\<response><br/>  \<kb_entry>2: Connect to VPN\</entry><br/>  \<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:<br/><br/>1. First, install the GlobalProtect VPN client. You can find this in our software center.<br/>2. Once installed, open the GlobalProtect application.<br/>3. In the server field, enter "vpn.ourcompany.com".<br/>4. Use your Active Directory (AD) credentials to log in - the same username and password you use for your email.<br/><br/>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><br/>\</response> |

</section>

## Chain prompts for complex tasks
Break down complex tasks into smaller, consistent subtasks. Each subtask gets Claude's full attention, reducing inconsistency errors across scaled workflows.