Few-Shot Examples and Chain-of-Thought Prompting
Explore how to apply few-shot examples and chain-of-thought prompting to guide Claude's reasoning for complex tasks. This lesson helps you design effective prompts with positive and negative examples, format them correctly, and distinguish visible reasoning from internal extended thinking to achieve reliable AI outputs.
A well-structured system prompt sets the rules. Examples show Claude what following those rules looks like in practice. These two mechanisms are complementary: rules constrain the space of valid outputs, and examples pull Claude toward the best output within that space. This lesson covers how to place and format examples for maximum effect, and how to instruct Claude to reason through complex tasks before committing to an answer. By the end of this lesson, we will be able to:
Place a few-shot example in the correct location and format for a given task
Write positive and negative examples that steer Claude away from common errors
Apply chain-of-thought instructions to tasks that require intermediate reasoning steps
Distinguish between chain-of-thought in the prompt and the extended thinking API feature
What few-shot examples do
A few-shot example is a completed input-output pair that Claude reads before it processes the actual request. It demonstrates the desired output, not just describes it. Claude infers the expected format, tone, level of detail, and handling of edge cases from the examples rather than from its interpretation of the written instructions. Three situations signal that few-shot examples are needed:
The output has a non-obvious structure. A JSON schema with nested arrays, specific field names, or unusual enum values benefits from a concrete example far more than a written description of the schema.
The task involves subtle judgment. Classifying support tickets ...