A comprehensive, practical guide to writing better prompts for large language models. Whether you're just starting out or looking to master advanced techniques, this guide covers everything from basic principles to production-ready patterns.
Large language models predict the next token in a sequence, one at a time. They don't "think" or "understand" in a human sense - they complete patterns based on training data. This single insight changes how you should write prompts.
Key implication:
The model is trying to continue your text in a plausible way. If your prompt looks like the beginning of a high-quality answer, the model is more likely to produce one. Frame your prompt as the start of the output you want, not just a request for it.
Every word in your prompt uses tokens and influences the response. The model weights recent context more heavily, so the most important instructions often belong at the end of the prompt, not just the beginning.
Temperature controls randomness. A temperature of 0 gives the most deterministic, predictable output. Temperature 1.0 adds creativity and variability. For factual tasks, use low temperature (0–0.3). For creative work, try 0.7–1.0.
Vague prompts get vague answers. Specify the exact format, length, tone, audience, and any constraints up front. "Write a 200-word professional email to decline a meeting" beats "write a polite email".
Tell the model who you are, who the output is for, and what it will be used for. Context shapes every word choice the model makes.
Break complex instructions into numbered steps or bullet points. Models follow structured instructions more reliably than walls of prose.
Examples are worth a thousand instructions. If you want a specific style, format, or level of detail, show one example of the output you expect.
Good prompting is a process. Start with a draft, look at what went wrong, add one constraint at a time until the output is right. Don't try to get it perfect on the first attempt.
Tell the model what NOT to do as well as what to do. "Do not include disclaimers", "avoid jargon", "don't ask clarifying questions" are often as useful as positive instructions.
Most effective prompts contain some or all of these components. You don't always need all of them, but knowing each one helps you diagnose what's missing when outputs fall short.
Who is the model in this interaction? "You are an expert Python developer with 10 years of experience in data pipelines."
What exactly do you want? Be as precise as possible about the action, scope, and boundaries.
Background information the model needs: industry, audience, prior work, constraints, or relevant data.
One or more input-output pairs showing the format and quality you expect. This is often the most powerful part.
How should the output be structured? List, JSON, markdown, table, paragraphs? Length limits?
The actual content to process: the document, code, text, or data to analyze.
Few-shot prompting includes 2–5 example input/output pairs before your actual request. It's one of the highest-leverage techniques available - often more effective than writing longer instructions.
# Example: Sentiment classification
Input: "The delivery was late but the product is great!"
Output: Mixed
Input: "Worst purchase I've ever made."
Output: Negative
Input: "Exceeded all my expectations, will buy again."
Output: Positive
Input: "It works, I guess."
Output:
Rules for good few-shot examples: (1) Keep them consistent in format - same structure every time. (2) Cover edge cases the model might get wrong. (3) Order matters - put the most representative examples last. (4) 3 examples usually beats 1; 8+ rarely helps more than 5.
For complex problems - math, logic puzzles, multi-step analysis - ask the model to reason step by step before giving a final answer. This dramatically improves accuracy.
Without Chain of Thought (often wrong):
"If a store sells apples at $1.20 each and oranges at $0.80 each, and I buy 5 apples and 7 oranges, how much do I pay? Answer:"
With Chain of Thought (much better):
"...how much do I pay? Think step by step before giving the final answer."
Magic phrases that trigger reasoning: "Think step by step", "Let's work through this carefully", "First, identify the key information. Then...", "Show your work."
For models with Extended Thinking (Claude 3.7+, o3), you can enable a separate reasoning phase via API parameters. This is more powerful than prompting for CoT - the model reasons internally before responding, often producing significantly better results on hard tasks with no extra prompting required.
The system prompt is a special message sent before the conversation that sets the model's behavior, persona, and constraints for the entire session. It takes priority over user messages.
A good system prompt template for most use cases:
# System Prompt Template
You are [specific role], an expert in [domain].
Your job is to [core task description].
Always:
- [positive behavior 1]
- [positive behavior 2]
Never:
- [thing to avoid 1]
- [thing to avoid 2]
Tone: [formal/casual/technical/friendly]
Response format: [free-form/bullet points/JSON/markdown]
Length: [concise (1–2 sentences)/detailed/comprehensive]
Keep system prompts focused. A 50-word system prompt often outperforms a 500-word one - every extra instruction dilutes attention on the important ones. Use prompt caching if your system prompt is long and reused across many requests (saves 50-90% on input costs).
| Format | When to Use | How to Request |
|---|---|---|
| JSON | Programmatic parsing, structured data extraction | "Return as valid JSON with keys: name, date, summary" |
| Markdown | Documentation, reports, rendered content | "Format with markdown headers and bullet points" |
| Numbered list | Step-by-step instructions, ranked items | "List 5 steps, numbered, one sentence each" |
| Table | Comparisons, feature matrices, structured data | "Present as a markdown table with columns: X, Y, Z" |
| Plain prose | Essays, summaries, creative writing | "Write in clear paragraphs, no lists or headers" |
Use structured outputs (JSON mode or function calling) when you need reliable programmatic parsing - don't rely on prose instructions alone if your code depends on a specific structure.
Run the same prompt multiple times and take the majority answer. This works especially well for math and factual questions where the model sometimes makes mistakes but would get it right most of the time. Computationally expensive but highly effective for high-stakes outputs.
Break complex tasks into sub-tasks. Instead of "write a complete marketing strategy", break it into: (1) Define target audience, (2) Identify channels, (3) Write messaging for each channel, (4) Create a 90-day calendar. Smaller, focused prompts produce better results than one giant prompt.
After the model produces an output, ask it to critique its own work: "What are the weaknesses of this answer?" or "Where could this be wrong?" Then ask it to improve based on that critique. This multi-turn pattern catches errors the model wouldn't catch in a single pass.
Assign increasingly specific roles in sequence: first ask the model to "act as a general business advisor", then "now you are specifically an M&A specialist with experience in SaaS acquisitions", then add domain context. Layering specificity often produces more expert-level outputs than trying to specify everything at once.
Instead of relying on the model's training data, retrieve relevant documents from your knowledge base and paste them into the prompt as context. This is the most reliable way to get factually accurate, up-to-date answers. Structure the prompt as: [Retrieved documents] + [Instruction: "Based only on the above, answer:"] + [Question].
Connect multiple LLM calls where the output of one becomes the input of the next. Example pipeline: (1) Extract key facts from a document → (2) Check facts against a knowledge base → (3) Generate a report using only verified facts. Chaining lets you build sophisticated workflows that would fail in a single prompt.
When prompting AI agents (systems that use tools and take multi-step actions), the stakes are higher. A badly worded agentic prompt can cause the agent to delete files, send emails, or make API calls you didn't intend.
Agentic Prompting Rules:
Asking multiple things in one prompt
Fix: Split multi-part tasks into separate, focused prompts. The model tends to drop the last few sub-tasks in a long list.
Being too polite or indirect
Fix: Say "Write a summary" not "Could you perhaps write a short summary if you don't mind?" LLMs respond to direct, clear instructions.
Expecting the model to know what's implicit
Fix: State the obvious. "Audience: non-technical executives" is not too basic - it's necessary.
Ignoring output length
Fix: Specify length: "in 3 bullet points", "in under 100 words", "as a comprehensive 2000-word report". Unconstrained length is often wrong.
Not iterating
Fix: Expecting a perfect output on the first try. Treat prompting as a debugging process: identify what's wrong, add a constraint, test again.
Using a flagship model for everything
Fix: Route simple tasks to cheap, fast models (Haiku, Flash, Mini). Save expensive models for complex reasoning.
<context>, <instructions>system_instruction fieldFor better reasoning
"Think step by step before answering."
For consistent format
Show 2–3 output examples before the real request.
For factual accuracy
Provide source documents. Ask to cite them.
For JSON output
Use structured outputs mode, not just instructions.
Temperature guide
Factual: 0–0.2 | Balanced: 0.5 | Creative: 0.8–1.0
Longer prompts cost more tokens. Use our tools to optimize: