Prompt Formulas for Better AI Workflow Results
Chain-of-Thought vs Tree-of-Thought vs ReAct
Use the right reasoning pattern. CoT handles most linear tasks. ToT explores branches when one path fails. ReAct loops with tools.
| Technique | When to use | Strengths | Weaknesses |
|---|---|---|---|
| Chain-of-Thought (CoT) | Math, logic, code, step-by-step analysis | Simple. Improves accuracy 10-40% on multi-step tasks. Low token cost. | Linear. Prone to hallucination on facts. No self-correction. |
| Tree-of-Thought (ToT) | Strategic planning, creative problem solving, Game of 24 | Explores multiple paths. Prunes bad branches. Strong on search-like tasks. | High token cost (10-50x). Complex to implement. Slower. |
| ReAct | Agentic workflows, tools, web search, dynamic data | Combines thought + action. Handles external feedback. Reduces hallucination. | Requires tool integration. More tokens (3-5x). Can loop. |
Structured Output Patterns
Tool calling beats raw JSON prompts on frontier models (Claude Opus 4.6, Sonnet 4.6, Grok 4.20, GPT-5.4). The model follows the schema exactly instead of guessing.[1]
- Native Structured Outputs / JSON Schema: Use for data extraction or final formatted answers. Constrained decoding guarantees valid output. Preferred in 2026.
- Tool / Function Calling: Define tools. Model decides when to call them. Best for agents that need to act. Combine with structured final response.
- Plain "Output JSON" in prompt: Works about 80-90% of the time. Avoid in production. Parse failures kill workflows.
- XML tags: Claude models respond strongly to <task>, <context>, <output> structure. Use on Anthropic models.
System Prompt Structure Template
This template works across Claude Opus 4.6, Sonnet 4.6, Grok 4.20, and GPT-5.4. Paste as system message. XML helps Claude. Clear roles help all models.
<system>
You are an expert [ROLE - one short phrase].
Goal: [One sentence describing success. Be specific.]
Constraints:
- [Constraint 1, be concrete]
- [Constraint 2]
- [Constraint 3]
Reasoning style: Think step by step. Consider alternatives when appropriate. If you need external data, use tools before concluding.
Output format: [Describe exactly. Use tool calling or structured schema when available.]
</system>
The first two lines set role and success criteria. Constraints prevent drift. Reasoning line activates useful patterns without forcing CoT on every reply. If the task needs tools, the model calls them.
Temperature and Top-p Settings
Change one at a time, and Low values for precision. Higher for exploration. Most workflows run best at 0.0-0.3.
| Use Case | Temperature | Top-p | Notes |
|---|---|---|---|
| Code generation, math, factual extraction | 0.0 - 0.2 | 0.1 - 0.3 | Deterministic. Minimal variance. Preferred on Claude Opus 4.6. |
| Code review, technical writing, analysis | 0.3 - 0.5 | 0.5 - 0.7 | Balanced. Good judgment without rambling. |
| Research synthesis, brainstorming | 0.6 - 0.8 | 0.8 - 0.9 | More ideas. Still coherent on GPT-5.4 and Grok 4.20. |
| Creative or highly exploratory tasks | 0.8 - 1.0 | 0.9 - 0.95 | High diversity. Test carefully. Token usage rises. |
Common Failure Modes
| Symptom | Cause | Fix |
|---|---|---|
| Model ignores instructions or format | Vague system prompt or buried rules | Put role, goal, and output format in the first 2-3 sentences. Use XML tags on Claude. |
| Hallucinated facts or sources | Pure CoT on knowledge-heavy task | Switch to ReAct. Force tool use for lookup. |
| Wanders off-topic or adds filler | No explicit constraints | List 3-4 hard constraints. Tell model to say "I don't know" instead of guessing. |
| Inconsistent or invalid JSON | "Output JSON" in user prompt only | Use native structured outputs or tool calling schemas. |
| Loops forever or repeats steps | Missing stop condition in ReAct | Add explicit "stop when you have enough information" or max iterations. |
| Shallow reasoning on complex task | Zero-shot or temperature too high | Add "think step by step" or few-shot examples. Drop temperature to 0.2. |
| Refuses or over-applies safety | Overly broad constraints | Narrow the role. Give concrete success criteria. |
Copy-Paste Prompt Templates
Code Review
You are a senior software engineer performing a security and correctness review.
Code to review:
[PASTE CODE HERE]
Review step by step:
1. Understand the intended functionality.
2. Check for bugs, edge cases, and off-by-one errors.
3. Look for security issues (injection, auth, secrets).
4. Suggest performance or readability improvements.
Output using tool calling or structured format with sections: summary, critical_issues, suggestions, rating (1-10).
Complex Multi-Step Reasoning
Solve this problem using chain-of-thought reasoning.
Problem: [INSERT PROBLEM]
First, list the key facts and constraints.
Then, break the problem into 3-5 smaller steps.
For each step, show your work and any assumptions.
Evaluate at least two different approaches.
Finally, give a clear answer with confidence (low/medium/high).
Do not skip steps.
Research Synthesis
Synthesize the following sources into a coherent summary.
Sources:
[SOURCE 1]
[SOURCE 2]
...
Task:
- Identify agreements and contradictions.
- Note which claims have strong evidence.
- Highlight gaps or open questions.
- Produce a final synthesis no longer than 400 words.
Use ReAct if you need to verify anything. Cite sources inline.
Structured Data Extraction
Extract the requested fields from the provided text. Use the exact schema.
Text:
[PASTE TEXT OR DOCUMENT]
Required fields:
- name: string
- date: YYYY-MM-DD or null
- amount: number or null
- category: one of [list options]
- notes: short summary
Return valid structured output only. If a field is missing, use null. Do not add extra text.
These templates run cleanly on current frontier models. Test one change at a time. The signal lives in the constraints and output schema.