Implementation Guide — Prompting Examples
This directory originally contained Python example scripts that were removed from this archive.
An AI assistant can recreate them by following the instructions below.
chain_of_thought.py
Purpose: Demonstrate chain-of-thought (CoT) prompting to improve reasoning on multi-step problems.
What to implement:
- Use the Anthropic SDK to call a Claude model.
- Show a baseline prompt (no CoT) vs. a CoT-triggered prompt (“Think step by step…”) on:
- A math word problem (e.g. calculating compound interest).
- A logic puzzle (e.g. river-crossing problem).
- Print both the prompt and the model’s response side-by-side.
- Optionally use
extended_thinking(budget_tokens) if using Claude 3.7+.
How to run: python chain_of_thought.py
Dependencies: anthropic
structured_output.py
Purpose: Show how to reliably extract structured JSON from Claude.
What to implement:
- Prompt Claude to extract structured data from an unstructured paragraph (e.g. a job posting →
{title, company, salary_range, requirements[]}). - Use two approaches:
- Prompt engineering: ask for JSON in the system prompt and parse with
json.loads(). - Tool-use / function-calling: define a tool schema and let Claude fill it.
- Prompt engineering: ask for JSON in the system prompt and parse with
- Validate the output with
pydantic(optional but recommended). - Print the parsed Python dict/model.
How to run: python structured_output.py
Dependencies: anthropic, pydantic (optional)