In This Handbook
Prompting: How We Steer LLMs
If an LLM is a predict-next-word engine that’s been trained and aligned to be helpful, then prompting is how we steer that engine to get the output we want. A useful analogy is to think of the LLM as a very talented but somewhat naive actor or improviser: it will continue any role or scenario you set up, but you (as the prompter) are the director giving the cues. Crafting those cues well is crucial. In this lesson, we’ll define what prompts are and how they condition the model’s behavior at runtime. In this lesson, we’ll explore different types of prompts, patterns and techniques, share best practices and common mistakes, and compare prompting to other ways of influencing an AI (like fine-tuning). By the end, you should have practical intuition for how to communicate your intent to an LLM effectively.
What Is prompting?
A prompt is basically the input text you feed into the model to elicit a response. Prompting is often described as “programming with natural language”. Instead of writing code or changing internal model weights, you are writing instructions or context in plain language to guide the model’s output. This is a form of runtime conditioning: you condition (influence) the model’s next-token predictions by providing specific context right when you query it. Because the model always tries to continue the given text in a plausible way, how you formulate that text has a huge impact on what it produces next.
ⓘ Prompting shapes token probabilities
Under the hood, prompting works by reshaping the probability distribution over the next token the model will generate. Every word, phrase, or instruction you include nudges the model toward certain continuations and away from others. Small wording changes can therefore lead to noticeably different outputs.
For example, if you prompt the model with just “The timeline of World War II:”, the continuation might be a factual list of events. If you prompt it with “Write a funny story about a cat who thinks it’s a history professor during World War II:”, the continuation will likely be humorous and narrative. The prompt sets the stage. Unlike training, which embeds patterns permanently, prompting is ephemeral as it only affects the output for that one interaction and leaves the model unchanged for the next request. This makes prompting very powerful for on-the-fly control. You can think of it as the model having read an enormous library, and your prompt is telling it, “Given all you know, speak in this context or persona and address this specific query.”
Types of prompts: Prompts can include several elements:
- Instructions: A direct command or request to the model. e.g., “Explain how a combustion engine works in simple terms.” This clearly tells the model what you want.
- Context: Supplemental information or data you provide that the model should use. e.g., giving a paragraph of text and then saying “Summarize the above passage.” The provided paragraph is context that guides the answer.
- Examples (Few-Shot prompting): Demonstrations of the task, so the model can infer the pattern. e.g., you might provide:
“Q: What is 2+2?
A: 4
Q: What is 3+5?
A: 8
Q: What is 7+6?
A: ”This prompt includes two examples of question-answer pairs before asking the model to answer the third question. The model will continue in kind and likely say “13”. This technique of providing examples in the prompt is known as few-shot learning via prompting, and it’s a way to improve accuracy on tasks by showing the model what you expect. - Role/contextual setup: Sometimes you preface the conversation with a role or scenario. e.g., “You are a helpful legal assistant. You have expertise in contract law. When answering, cite relevant laws.” This primes the model to respond in a certain tone or with certain knowledge (the model will play along with the role it’s given, using its training data about that role).
- Format directives: Telling the model how to format its answer. e.g., “Answer in bullet points” or “Give the response as JSON.” The model will try to comply with these if possible, formatting the output accordingly.
A prompt can combine all of the above: e.g., Instruction: “You are a translator.” Context: “[some text in English]” Instruction 2: “Translate the above text into Spanish. Respond only with the translated text.” In one prompt, we’ve set a role, provided content, and asked for a specific operation and format.
Prompting is basically the interface through which we “program” the model for a particular query. It’s amazing how much the same fixed model can do just by changing the prompt. This is why prompt design is considered an art and science of its own (often called prompt engineering).
ⓘ Prompts vs. prompt templates
Prompting can be done ad hoc (e.g., typing a question into a chat interface), but production systems usually rely on prompt templates. A prompt template is a structured prompt with placeholders (for user input, retrieved data, or parameters) that ensures consistency across many requests. Most real-world AI systems use templates rather than free-form prompts.
Prompt patterns and techniques
Over time, practitioners have identified patterns that tend to yield better results. Here are some common ones:
- Zero-shot vs. few-shot: Zero-shot prompting means you just give instructions without examples (“Translate this…”, “Explain that…” etc.). Few-shot prompting means you include some examples of the task done correctly in the prompt, as illustrated above for math Q&A. Few-shot can dramatically improve performance for certain tasks because it gives the model specific context about what you’re expecting. It’s like telling the model: “See these examples? Do it like that.” The downside is it uses up space in the context window, but even 1-2 examples can help steer the model, especially for tasks like formatting or following a specific style.
ⓘ Prompts consume context window space
Everything in a prompt (instructions, examples, system messages, and user input) must fit within the model’s context window. Few-shot prompting can improve accuracy, but each example uses up space. If the prompt becomes too long, earlier information may be truncated, reducing effectiveness.
- Role-based prompting: Assigning the model a persona or role influences the style and knowledge of the output. For example, instructing the model to act as an “experienced software engineer” will result in a technical and concise response, while using a role like a “kindergarten teacher” will produce a simpler explanation for the same topic. This works because the model has learned and can tap into the characteristic styles associated with various roles.
- Chain-of-thought (CoT) prompting: Encourage the model to think step by step (e.g., “Let’s solve this step by step:”). This prompt engineering technique, which asks the model to output its reasoning process before the final answer, significantly improves performance on complex math and logic tasks. Researchers found that simply adding “Let’s think step by step” increased answer correctness by prompting the model to emulate multi-step reasoning observed in its training data. While the resulting reasoning text may not always be perfect, it’s helpful for tracking the process and prevents the model from skipping necessary steps.
ⓘ Reasoning text vs. internal reasoning
When a model outputs step-by-step reasoning, that text is a generated explanation. It is not a direct window into the model’s internal decision process. While chain-of-thought prompting can improve accuracy and transparency, the reasoning shown may be incomplete, approximate, or simplified.
Structured output prompts: To ensure a specific output format (e.g., JSON, HTML, or a table), include it explicitly in the prompt (e.g., “Provide the answer in JSON format…”). Similarly, request specific structures like bullet points (“List 3 key points…”) or output without explanation (“Return only the SQL query…”). Being explicit about the desired format improves the structure of the model’s output.
Avoiding ambiguity: Good prompts are unambiguous. Vague instructions like, “Tell me about Python,” can lead to confusion (programming language or snake?). A better prompt is “Explain the Python programming language, focusing on its main features and use cases, in 2-3 paragraphs.” This clearly defines the context, scope, and length, ensuring a satisfactory and targeted response.
Using system/setup prompts: LLM interfaces often allow a system message (like in OpenAI’s ChatGPT API) to globally set the assistant’s behavior (e.g., enforcing politeness or character). Using this is wise, as it avoids repeating instructions. For one-shot prompts, you can simply prepend this instruction text.
Let’s illustrate a combined prompt that employs several of these techniques:
Prompt:
“You are a travel assistant. A user will ask you for a travel itinerary. Provide a 3-day itinerary in a numbered list. The itinerary should include hotels, restaurants, and activities. Use a friendly tone.
Example Format:
Day 1: City – Morning: …; Afternoon: …; Evening: …
Day 2: City – Morning: …; Afternoon: …; Evening: …
Day 3: City – Morning: …; Afternoon: …; Evening: …
User request: I want to visit Tokyo for 3 days. What should I do?”
In this prompt, we: set a role (“travel assistant”), give clear instructions (3-day itinerary, include specific types of info, friendly tone), specify an output format with an example template, and finally present the actual user request. A well-trained LLM with this prompt will likely produce a nicely formatted 3-day Tokyo itinerary following that structure.
Prompting best practices vs. common mistakes
Best Practices:
- Be specific: State your exact needs clearly (e.g., length, format, details). Vague prompts lead to vague outputs and can increase inaccuracies.
- Provide context: Include any necessary background (e.g., text, data) directly in the prompt. Models don’t retain memory of your files.
- Use examples for clarity: Guide the model on complex or format-sensitive tasks by providing input/output examples; the model will pattern-match.
Iterate and refine: Expect to adjust your prompt based on the initial output (e.g., lengthen, shorten, remove unwanted info). Tweak until you get the desired result. - Anticipate errors: Preemptively instruct the model to avoid common pitfalls (e.g., “Don’t guess,” “Use only the provided text”). This reduces fabrication.
Keep prompts clear and concise: Avoid irrelevant information or overly complex language that could confuse the model. - Leverage system/developer instructions: Use separate, high-level settings (if available) for consistent policies (e.g., tone, security constraints) to keep the user query clean.
Common mistakes:
Here are common prompting mistakes to avoid:
- Being too vague: Don’t just say “Tell me about Python.” Be specific, e.g., “Explain the Python programming language, focusing on its main features and use cases, in 2-3 paragraphs.
- Embedding contradictory instructions: Avoid confusing phrasing like, “Explain quantum computing simply, and don’t simplify too much.” Clarify the target audience instead (e.g., “for someone with a high-school science background”).
- Multiple questions at once without clarity: Asking too many questions in one prompt (e.g., “What is X, how does it work, who invented it, and when will it be mainstream?”) can lead to messy answers. Break them down or use a numbered list.
- Using negations and tricky wording: Models can misinterpret negations (e.g., “Don’t include jokes”). Phrase positively what you do want (e.g., “Provide a serious explanation with no humor.”). Simple wording is best.
- Relying on the model’s memory of previous turns when none given: In a fresh session, the model has no prior context. Always include relevant history or context for ongoing tasks.
- Assuming factual accuracy without verification: Never blindly trust the output, especially for facts. Always double-check, or explicitly prompt the model to cite sources or double-check itself.
ⓘ Prompting vs. knowledge limits
Prompting can change how a model responds, but not what it knows. No amount of clever phrasing can make a model aware of events beyond its training data or reliably recover missing facts. When up-to-date or authoritative information is required, prompting must be combined with external data sources or tools.
- Prompting for disallowed content or ignoring safety guidelines: Do not prompt for disallowed or harmful content; the model will refuse. If a legitimate request is refused due to misclassification, reword the prompt for clarity.
Prompting vs. fine-tuning
Prompting is one way to get the behavior you want without changing the model’s weights. Fine-tuning, on the other hand, means updating the model’s parameters by additional training (we’ll cover that in a later lesson). It’s worth understanding when you’d use prompting versus fine-tuning.
- Flexibility: Prompting is fast, flexible, and on-the-fly, suitable for one-off results or quick iterations. Fine-tuning is a heavier process, better for recurring tasks where you want the model to be inherently good without complex prompts.
- Depth of change: Prompting guides style within the model’s existing knowledge. Fine-tuning can teach new patterns, styles (like Shakespearean English), or domain-specific knowledge that prompts alone cannot achieve.
- Prompt complexity: Fine-tuning can simplify usage by baking desired behavior into the model, allowing for simple questions rather than long, elaborate prompts with examples. Prompt engineering supports, while fine-tuning tailors the model’s knowledge.
Don’t fine-tune if prompting meets the need (e.g., one-off JSON formatting), or if you lack sufficient training data, as few-shot prompting might perform better and prevent overfitting. Prompting is ideal with limited custom data.
Think of prompting as the first resort for getting what you need from an LLM – it’s fast, free (in the sense of not requiring a training pipeline), and doesn’t risk altering the model’s other behaviors. Fine-tuning is a more involved step to consider if prompts can’t get you there or are too cumbersome.
Prompting is a skill that improves with practice. The more you interact with LLMs, the better you get at anticipating how a prompt might be interpreted. In essence, you’re learning to communicate with an alien mind that is extremely knowledgeable but follows odd rules (the rules of next-word probability). Both technical folks and general users can become adept prompt crafters – you don’t need to know how the model works internally (though it helps) as long as you can observe its outputs and adjust accordingly. It’s a bit like learning to ask questions of a knowledgeable person: clarity and context yield better answers.
We’ve only just begun to explore the potential of prompts. Ready for more? Check these out:
With a solid grasp on prompting, you can do a lot without ever altering the model itself. However, in some cases, you might want the model itself to change. That’s where training and fine-tuning come in. In the next lesson, we’ll take a closer look at how these models are trained, and what that means for their behavior and limits.
I’m Fahim, a software engineer specializing in generative AI, system design, and responsible AI adoption.