Prompting is the art of directing an LLM's attention. Instead of retraining massive models, we can change their behavior completely just by structuring our text prompts.
**System Prompts** (also called system instructions) define the character, boundaries, guidelines, and output format of the AI before any user message is sent. They establish high-level behavioral constraints (e.g., *"You are a helpful chemistry tutor who never gives the answer directly but guides the student step-by-step"*).
LLMs are excellent at learning patterns on the fly. In a standard "Zero-Shot" prompt, you ask a question directly. In **Few-Shot Prompting**, you provide 2 to 5 examples of input-output pairs inside the prompt. This teaches the model the exact style, tone, and format you expect.
If you ask an LLM a complex math or logic question directly, it may output a wrong answer because it attempts to predict the final answer immediately. **Chain of Thought** prompting instructs the model to *"think step-by-step"* before outputting the final result. This allows the model to compute intermediate reasoning steps, drastically increasing accuracy.
Most weak prompts fail for the same reason: the model has to guess something you never said. A reliable prompt usually states five things explicitly: the role the model should take, the task, the context it needs (the text to work on, the audience, any constraints), the output format, and what to do when the input is unclear. Compare a vague request with a specified one:
# Vague
Summarize this support ticket.
# Specified
You are a support triage assistant.
Read the ticket between the <ticket> tags and return JSON with exactly these keys:
"summary" : one sentence, max 25 words
"category" : one of "billing", "bug", "feature_request", "other"
"urgent" : true only if the customer reports data loss or being locked out
If the ticket is empty or not a support request, return {"category": "other", "summary": "", "urgent": false}.
<ticket>
{ticket_text}
</ticket>Notice the delimiter tags around the untrusted text. They make it clear where your instructions end and the data begins, which makes the prompt easier to maintain and harder to derail with text that happens to look like an instruction.
In an application you rarely write a prompt by hand; you assemble it from a template and a list of examples. Keeping the examples as data makes them easy to test, swap and extend. This is the same pattern the coding challenge below asks you to build:
EXAMPLES = [
("The delivery was fast and the packaging was perfect.", "POSITIVE"),
("It stopped working after two days.", "NEGATIVE"),
("Arrived on time, but the box was crushed.", "NEGATIVE"),
]
def build_prompt(text):
lines = ["Classify the sentiment of each review as POSITIVE or NEGATIVE.", ""]
for review, label in EXAMPLES:
lines.append(f'Review: "{review}"')
lines.append(f"Sentiment: {label}")
lines.append("")
lines.append(f'Review: "{text}"')
lines.append("Sentiment:")
return "\n".join(lines)
print(build_prompt("The battery died in 10 minutes."))The prompt ends with Sentiment: so the most natural continuation is the label itself. Examples should cover the cases you care about (including a tricky one, like the mixed review above), keep an identical format, and be balanced across labels. If every example is POSITIVE, the model leans toward POSITIVE.
Chain of thought helps most on multi-step arithmetic, logic and planning questions. Consider: "A shop sells pens at 3 for $2. How much do 12 pens cost?" A step-by-step prompt makes the model work through it: 12 pens is 4 groups of 3, 4 groups at $2 each is $8. Two practical points:
ANSWER:". Your code can then parse just that line.Specify role, task, context, format and edge cases. Use a system prompt for standing rules, few-shot examples to pin down format and tone, and step-by-step reasoning for multi-step problems. Then treat prompts like code: keep them in templates, test them against a fixed set of inputs, and change one thing at a time.
Let's simulate a few-shot sentiment analyzer using standard string formatting in Python!
few_shot_prompt.Input: "Great service!" -> Output: POSITIVE).Input: "The battery died in 10 minutes." -> Output: and print the prompt.Verify your structured template in the execution console on the right!