System Prompts with Explicit Criteria: Worked Example — Prompt Engineering & Structured Output (Claude Certified Architect)
System Prompts with Explicit Criteria — Worked Example In the context of the Claude Certified Architect - Foundation certification, mastering prompt...
System Prompts with Explicit Criteria — Worked Example
In the context of the Claude Certified Architect - Foundation certification, mastering prompt engineering is essential to design reliable AI solutions. This worked example demonstrates how to craft a system prompt with explicit criteria to improve precision and enforce structured output for a realistic extraction and review task.
Scenario
Suppose you are designing a Claude-based application to extract key information from customer feedback emails. The goal is to reliably extract three fields:
- Customer Name
- Issue Description
- Urgency Level (Low, Medium, High)
The output must be in a strict JSON format for downstream processing and review.
Step 1: Define Explicit Criteria in the System Prompt
Start by clearly specifying the extraction requirements and output format in the system prompt. Explicit criteria reduce ambiguity and false positives.
Example system prompt snippet:
"You are an AI assistant extracting data from customer emails. Extract the Customer Name, a concise Issue Description summarizing the problem, and the Urgency Level which must be one of: Low, Medium, or High. Output the result only as a JSON object with keys: 'customer_name', 'issue_description', 'urgency_level'. Do not add any explanation or extra text."
Step 2: Incorporate Few-Shot Examples
Provide 2-3 few-shot examples within the system prompt to demonstrate the expected input-output pattern. This helps the model learn consistent formatting and interpretation.
Example:
{ "input": "Hi, this is Jane Doe. My internet is down since yesterday.", "output": { "customer_name": "Jane Doe", "issue_description": "Internet outage since yesterday", "urgency_level": "High" } }
Repeat for other examples with varying urgency levels and issue types.
Step 3: Enforce Structured Output Using JSON Schema
Define a JSON schema that the output must conform to, specifying required fields and enumerated values for urgency_level. This schema can be used programmatically to validate outputs and trigger retries if necessary.
Step 4: Implement Validation, Retry, and Feedback Loops
After receiving the AI's output, validate it against the JSON schema. If the output is malformed or fields are missing, automatically retry the prompt with a clarifying system message or escalate for human review.
Step 5: Design Efficient Batch Processing
For processing multiple emails, batch inputs and use a single prompt with clear separators and instructions for each entry. This improves throughput and consistency.
Step 6: Multi-Pass or Multi-Instance Review Architecture
To ensure extraction quality, design a multi-pass system where initial extraction is followed by a secondary review agent that checks for inconsistencies or missing data, possibly requesting clarifications or corrections.
Worked Example Summary
- Compose system prompt with explicit extraction criteria and output format.
- Embed few-shot examples demonstrating correct JSON output.
- Define JSON schema to validate outputs.
- Implement validation and retry logic to handle errors.
- Batch process inputs for efficiency.
- Use multi-pass review to enhance reliability.
This approach ensures precise, structured extraction from unstructured text, aligning with the Claude Certified Architect - Foundation skillset for prompt engineering and structured output enforcement.
More in this topic
Ready to test your knowledge?
Put what you've learned into practice with a quick quiz and track your progress.
Test your knowledge →