Prompting 101
Look, we’ve all been there — staring at that blank prompt, wondering how to get the AI to actually understand what we want. It’s like trying to explain something to someone who’s brilliant but also completely new to your world. That’s where the art of prompting comes in. In this guide, I’ll walk you through everything I’ve learned about getting the most out of Large Language Models, particularly Claude this past week. Don’t worry if you’re just getting started — we’ll break it all down into bite-sized pieces that actually make sense.
Think of this as your practical field guide to prompt engineering. No fancy jargon, just real techniques that work. From basic conversations to complex tasks, you’ll learn how to speak AI’s language while still being yourself. So whether you’re a developer looking to level up your skills or just someone curious about making AI tools work better for you, stick around. Trust me, by the end of this, you’ll be crafting prompts like a pro.
Every LLM Provider today mainly offer messages API; we will go through some basic thumb rules to remember
We will be using Anthropic mostly for this guide though the techniques are concepts applicable on any LLM
Anthropic offers two APIs, the legacy Text Completions API and the current Messages API. For this tutorial, we will be exclusively using the Messages API.
Basic Format for Messages while using Anthropic
message = client.messages.create(
model=MODEL_NAME,
max_tokens=2000,
temperature=0.5,
system=system_prompt,
messages=[
{"role": "user", "content": prompt}
]
)
return message.content[0].text
messages
: an array of input messages. models are trained to operate on alternatinguser
andassistant
conversational turns. When creating a newMessage
, we specify the prior conversational turns with the messages parameter, and the model then generates the nextMessage
in the conversation.- Each input message must be an object with a
role
andcontent
. You can specify a singleuser
-role message, or you can include multipleuser
andassistant
messages. The first message must always use theuser
role.
You can have multiple user
& assistant
pairs in a prompt (as if simulating a multi-turn conversation).
System Prompts
We can also use system prompts. A system prompt is a way to provide context, instructions, and guidelines to any LLM before presenting it with a question or task in the “User
” turn.
LLM responds best to clear and direct instructions.
Think of LLM like any other human that is new to the job. It has no context on what to do aside from what you literally tell it. Just as when you instruct a human for the first time on a task, the more you explain exactly what you want in a straightforward manner to it, the better and more accurate it’s response will be.” When in doubt, follow the Golden Rule of Clear Prompting:
Show your prompt to a colleague or friend and have them follow the instructions themselves to see if they can produce the result you want. If they’re confused, Llm’s confused.
Role Prompting
Continuing the theme of LLM having no context aside from what you say, it’s sometimes important to prompt llm to inhabit a specific role (including all necessary context). This is also known as role prompting. The more detail to the role context, the better.
Priming LLM with a role can improve it’s performance in a variety of fields, from writing to coding to summarizing. It’s like how humans can sometimes be helped when told to “think like a ______”. Role prompting can also change the style, tone, and manner of it’s response.
Role prompting can happen either in the system prompt or as part of the User message turn.
You can use role prompting as a way to get LLM to emulate certain styles in writing, speak in a certain voice, or guide the complexity of its answers. Role prompting can also make Llm better at performing math or logic tasks.
Prompt Templates
Oftentimes, we don’t want to write full prompts, but instead want prompt templates that can be modified later with additional input data before submitting to Llm. This might come in handy if you want Llm to do the same thing every time, but the data that Llm uses for its task might be different each time.
Luckily, we can do this pretty easily by separating the fixed skeleton of the prompt from variable user input, then substituting the user input into the prompt before sending the full prompt to Llm.
Why would we want to separate and substitute inputs like this? Well, prompt templates simplify repetitive tasks. Let’s say you build a prompt structure that invites third party users to submit content to the prompt (in this case the animal whose sound they want to generate). These third party users don’t have to write or even see the full prompt. All they have to do is fill in variables.
Prompt templates can have as many variables as desired!
Formatting Outputs
Llm can format its output in a wide variety of ways. You just need to ask for it to do so!
One of these ways is by using XML tags to separate out the response from any other superfluous text. You’ve already learned that you can use XML tags to make your prompt clearer and more parseable to Llm. It turns out, you can also ask Llm to use XML tags to make its output clearer and more easily understandable to humans.
LLMs also excels at using other output formatting styles, notably JSON
.
Thinking Step by Step
If someone woke you up and immediately started asking you several complicated questions that you had to respond to right away, how would you do? Probably not as good as if you were given time to think through your answer first.
Guess what? LLMs are the same way.
Giving LLM time to think step by step sometimes makes it more accurate, particularly for complex tasks. However, thinking only counts when it’s out loud. You cannot ask llm to think but output only the answer — in this case, no thinking has actually occurred.
Examples
Giving Llm examples of how you want it to behave (or how you want it not to behave) is extremely effective for:
- Getting the right answer
- Getting the answer in the right format
This sort of prompting is also called “few shot prompting”. You might also encounter the phrase “zero-shot” or “n-shot” or “one-shot”. The number of “shots” refers to how many examples are used within the prompt.
Hallucination
Some bad news: Llm sometimes “hallucinates” and makes claims that are untrue or unjustified. The good news: there are techniques you can use to minimize hallucinations. Below, we’ll go over a few of these techniques, namely:
- Giving Llm the option to say it doesn’t know the answer to a question
- Asking Llm to find evidence before answering
However, there are many methods to avoid hallucinations, including many of the techniques you’ve already learned in this course. If Llm hallucinates, experiment with multiple techniques to get Llm to increase its accuracy.
A great way to reduce hallucinations on long documents is to make Llm gather evidence first.
For example, we can tell Llm to first extract relevant quotes, then base its answer on those quotes. Telling Llm to do so here makes it correctly notice that the quote does not answer the question.
Sometimes, Llm’s hallucinations can be solved by lowering the temperature
of Llm's responses. Temperature is a measurement of answer creativity between 0 and 1, with 1 being more unpredictable and less standardized, and 0 being the most consistent.
Asking Llm something at temperature 0 will generally yield an almost-deterministic answer set across repeated trials (although complete determinism is not guaranteed). Asking Llm something at temperature 1 (or gradations in between) will yield more variable answers. Learn more about temperature and other parameters here.
Not all prompts need every element of the following complex structure. We encourage you to play around with and include or disinclude elements and see how it affects Llm’s response. It is usually best to use many prompt elements to get your prompt working first, then refine and slim down your prompt afterward.
Chain complex prompts for stronger performance
When working with complex tasks, Llm can sometimes drop the ball if you try to handle everything in a single prompt. Chain of thought (CoT) prompting is great, but what if your task has multiple distinct steps that each require in-depth thought?
Enter prompt chaining: breaking down complex tasks into smaller, manageable subtasks.
Why chain prompts?
- Accuracy: Each subtask gets Llm’s full attention, reducing errors.
- Clarity: Simpler subtasks mean more precise instructions and outputs.
- Traceability: Easily pinpoint and fix issues in your prompt chain.
When to chain prompts
Use prompt chaining for multi-step tasks like research synthesis, document analysis, or iterative content creation. When a task involves multiple transformations, citations, or instructions, chaining prevents Llm from dropping or mishandling steps.
Remember: Each link in the chain gets Llm’s full attention!
How to chain prompts
- Identify subtasks: Break your task into distinct, sequential steps.
- Structure with XML for clear handoffs: Use XML tags to pass outputs between prompts.
- Have a single-task goal: Each subtask should have a single, clear objective.
- Iterate: Refine subtasks based on Llm’s performance.
Example chained workflows:
- Multi-step analysis: See the legal and business examples below.
- Content creation pipelines: Research → Outline → Draft → Edit → Format.
- Data processing: Extract → Transform → Analyze → Visualize.
- Decision-making: Gather info → List options → Analyze each → Recommend.
- Verification loops: Generate content → Review → Refine → Re-review.
For tasks with independent subtasks (like analyzing multiple docs), create separate prompts and run them in parallel for speed.
Essential tips for long context prompts
- Put long-form data at the top: Place your long documents and inputs (~20K+ tokens) near the top of your prompt, above your query, instructions, and examples. This can significantly improve Llm’s performance across all models.
Queries at the end can improve response quality by up to 30% in tests, especially with complex, multi-document inputs.
- Structure document content and metadata with XML tags: When using multiple documents, wrap each document in
<document>
tags with<document_content>
and<source>
(and other metadata) subtags for clarity. - Ground responses in quotes: For long document tasks, ask Llm to quote relevant parts of the documents first before carrying out the task. This helps Llm cut through the “noise” of the document’s contents.
Remember to treat your LLM like a new teammate — clear instructions get you precise results. Keep your prompts direct, use examples when needed, and don’t be afraid to experiment with roles and personas.
For complex tasks, breaking things down into steps usually works better than throwing everything at once. And when accuracy matters, make the LLM show its work through step-by-step thinking.
The real magic happens when you start combining these techniques — maybe using role prompting with structured outputs or chaining prompts together for multi-step tasks. Play around and see what works for your specific needs.