Back to Library
PromptingIntermediate
Elicit Chain-of-Thought Reasoning
Tell Claude to "think step by step" or use `<thinking>` tags to get more accurate answers for complex problems.
reasoningchain-of-thoughtanalysis
The Strategy
Complex analytical tasks benefit enormously from explicit reasoning chains. Forcing step-by-step output reduces hallucinations because each step is constrained by the previous one.
prompt.txt
<task>
Analyze the following algorithm and determine its time complexity.
Think through each step carefully before giving your final answer.
</task>
<code>
function findDuplicates(arr: number[]): number[] {
const seen = new Set<number>();
const duplicates: number[] = [];
for (const n of arr) {
if (seen.has(n)) duplicates.push(n);
else seen.add(n);
}
return duplicates;
}
</code>
<output_format>
1. Step-by-step reasoning
2. Final complexity (Big-O)
3. Space complexity
</output_format>You might also need
PromptingBeginner
Use XML Tags for Structure
Claude is specifically trained to recognize and parse XML tags to separate instructions from content. Wrapping your prompt in named sections removes ambiguity.
xmlstructureclarity
View snippet
PromptingBeginner
Use Negative Constraints
Tell Claude what NOT to do. "Do not add comments", "Do not use any external libraries" — negative constraints are just as powerful as positive ones.
constraintsguardrailsfocused-output
View snippet