Quick Reference 01

Prompt Engineering

Quick reference for prompt patterns, templates, system prompts, and parameter tuning.

7 min readAI FundamentalsQuick ReferenceDownload PDF

Core Prompt Patterns

Prompt patterns are reusable strategies for structuring your instructions to an LLM. Choosing the right pattern is the single highest-leverage decision you make — it determines whether the model reasons carefully or guesses wildly.

PatternDescriptionBest For
Zero-shotNo examples, just instructionSimple tasks, capable models
One-shotSingle example providedFormat demonstration
Few-shot2-6 examples providedComplex formatting, edge cases
Chain-of-Thought (CoT)"Think step by step"Math, logic, reasoning
Tree-of-Thought (ToT)Explore multiple reasoning pathsComplex problem solving
Self-consistencySample multiple CoT, majority voteHigh-stakes reasoning
ReActReason + Act in alternating stepsTool-using agents
Skeleton-of-ThoughtOutline first, then expandLong-form generation

Zero-Shot vs Few-Shot Decision

The most common mistake in prompt engineering is providing too many examples when none are needed, or providing none when the model clearly needs guidance. This decision tree helps you choose the right approach for your task.

Is the task straightforward and well-defined?
  YES -> Zero-shot (add "Think step by step" if reasoning needed)
  NO  -> Does the output need a specific format?
           YES -> Few-shot (2-3 examples showing format)
           NO  -> Does it involve nuanced judgment?
                    YES -> Few-shot with edge cases
                    NO  -> One-shot with clear instructions

Chain-of-Thought Templates

Chain-of-thought prompting forces the model to show its reasoning before giving an answer. This dramatically improves accuracy on math, logic, and multi-step reasoning tasks — often turning a wrong answer into a correct one.

Basic CoT

Q: {question}
A: Let's think step by step.

Structured CoT

Solve the following problem. Show your reasoning in these steps:
1. Identify the key information
2. Determine the approach
3. Execute step by step
4. Verify the answer

Problem: {problem}

Self-Consistency (with CoT)

Generate 5 independent solutions to this problem.
For each, think step by step.
Then compare all answers and select the most common result.

System Prompt Architecture

The system prompt is your contract with the model — it defines who it is, what it does, and how it behaves. A well-structured system prompt eliminates 80% of output quality issues before they happen.

Anatomy of an Effective System Prompt

You are {role} with expertise in {domain}.

## Task
{What to do}

## Constraints
- {Constraint 1}
- {Constraint 2}

## Output Format
{Exact format specification}

## Examples
Input: {example_input}
Output: {example_output}

System Prompt Checklist

ElementPurposeRequired?
Role definitionSets persona and expertiseYes
Task descriptionCore instructionYes
Output formatControls structureYes
ConstraintsBoundaries and rulesRecommended
ExamplesDemonstrates expected behaviorRecommended
Error handlingWhat to do with bad inputOptional
Tone/styleVoice and registerOptional

Temperature and Sampling Parameters

Temperature and sampling parameters control how the model selects the next token. Getting these wrong means either robotic, repetitive outputs (too low) or hallucinated, incoherent ones (too high). Most production issues trace back to incorrect parameter settings.

ParameterRangeLow Value EffectHigh Value Effect
temperature0.0 - 2.0Deterministic, focusedCreative, diverse
top_p0.0 - 1.0Narrow token selectionWider token selection
top_k1 - NVery focusedMore diverse
frequency_penalty-2.0 - 2.0Allows repetitionPenalizes repetition
presence_penalty-2.0 - 2.0Allows topic revisitsEncourages new topics
TaskTemperaturetop_pNotes
Code generation0.0 - 0.20.95Deterministic preferred
Data extraction0.01.0Exact outputs needed
Creative writing0.7 - 1.00.95Diversity matters
Conversation0.5 - 0.70.9Balanced
Brainstorming0.9 - 1.21.0Maximum creativity
Classification0.01.0Consistency needed
Translation0.1 - 0.30.95Accuracy first

Rule of thumb: Set temperature OR top_p, not both. Use temperature for most cases.

Prompt Templates by Use Case

These are battle-tested templates for the most common LLM tasks. Copy, paste, and customize — they handle the structural patterns so you can focus on your specific domain requirements.

Classification

Classify the following text into exactly one category:
Categories: {list}

Text: "{input}"

Respond with only the category name, nothing else.

Extraction

Extract the following fields from the text below.
Return as JSON. Use null for missing fields.

Fields: {field_list}

Text: "{input}"

Summarization

Summarize the following text in {N} bullet points.
Each bullet should be one concise sentence.
Focus on: {key_aspects}

Text: "{input}"

Code Generation

Write a {language} function that {description}.

Requirements:
- {req1}
- {req2}

Input: {input_type}
Output: {output_type}

Include error handling and type hints.

Output Formatting Tricks

Unstructured LLM output is the #1 source of downstream bugs in production systems. These formatting techniques ensure your model returns parseable, consistent output every time.

TechniquePrompt FragmentUse Case
JSON mode"Respond in valid JSON only"Structured data
XML tags"Wrap answer in <answer> tags"Easy parsing
Markdown table"Format as a markdown table"Comparisons
Numbered list"List exactly N items"Controlled output
Delimiter"Separate sections with ---"Multi-part output
SchemaProvide JSON SchemaStrict structure

Advanced Techniques

When a single prompt can't handle the full complexity of your task, these techniques let you decompose, delegate, and iterate. Prompt chaining alone can turn a 60% accuracy task into a 95% one.

Prompt Chaining

Step 1: Extract key entities -> {entities}
Step 2: For each entity, gather context -> {context}
Step 3: Synthesize into final answer using {entities} + {context}

Meta-Prompting

You are a prompt engineer. Write the optimal prompt for an LLM
to accomplish this task: {task_description}

The prompt should include:
- Clear role definition
- Step-by-step instructions
- Output format specification
- 2-3 examples

Negative Prompting

Do NOT:
- Include disclaimers or warnings
- Use bullet points
- Exceed 100 words
- Mention that you're an AI

Token Optimization

Every token costs money and adds latency. In production systems handling millions of requests, a 30% reduction in prompt tokens can save thousands of dollars per month without sacrificing quality.

StrategySavingsTrade-off
Abbreviate instructions20-40%May reduce clarity
Remove examples30-50%Lower output quality
Use shorter delimiters5-10%Minimal
Compress system prompt15-30%Harder to maintain
Reference by name10-20%Needs model knowledge

Common Pitfalls

These are the mistakes every practitioner makes at least once. Bookmark this table — when your LLM output looks wrong, the fix is almost always here.

PitfallProblemFix
Vague instructionsInconsistent outputsBe specific about format and content
Too many constraintsModel ignores somePrioritize, reduce to essentials
No output formatUnparseable responsesAlways specify expected format
Conflicting instructionsConfused modelReview for contradictions
Over-long promptsToken waste, diluted focusTrim to essentials
No error handlingCrashes on edge casesAdd "If unsure, respond with..."
Assuming model knowledgeIncorrect outputsProvide context, don't assume
Temperature too high for factual tasksHallucinationsUse 0.0-0.2 for factual work
Few-shot with bad examplesModel learns wrong patternsVerify examples are correct
Ignoring token limitsTruncated outputCalculate: input + expected output < max

Evaluation Quick Checks

Before shipping any prompt to production, run these five checks. A prompt that works once in a playground can fail spectacularly at scale — these checks catch the gaps.

CheckMethod
ConsistencyRun same prompt 5x, compare outputs
Edge casesTest with empty, long, adversarial input
Format complianceParse output programmatically
Factual accuracySpot-check claims
Instruction followingDoes output match all constraints?

Quick Reference: Prompt Length Guidelines

Context windows are not infinite — and models don't attend equally to all content. Understanding your token budget prevents truncated outputs and ensures the model actually reads your most important instructions.

Model ContextEffective Prompt BudgetLeave for Output
4K tokens2K-3K1K-2K
8K tokens5K-6K2K-3K
32K tokens20K-25K7K-12K
128K tokens80K-100K28K-48K
200K tokens120K-160K40K-80K

Remember: Longer context windows do not mean the model attends equally to all content. Place critical instructions at the beginning and end of the prompt.