What Is Prompt Engineering? A Practical Guide With Examples
Prompt engineering is writing instructions that get reliable results from an AI model. The techniques that actually work — clear tasks, context, examples (few-shot), structure, letting the model think, and testing — with before-and-after examples, and how it differs from context engineering.
Prompt engineering means writing the instructions you give an AI model so that it reliably does what you want. It sounds grand; in practice it's mostly clear writing plus testing.
It matters in two places:
- When you use an AI tool — ChatGPT, Claude, an AI coding assistant.
- When you build an AI feature into an app, where the same prompt runs thousands of times and has to work every time.
The techniques that actually work
1. Say exactly what you want
The most common failure is vagueness. Compare:
Write something about our product.
Write a 3-sentence description of our invoicing app for the top of the homepage. Audience: freelancers who hate admin. Tone: plain and friendly, no buzzwords. End with a reason to sign up.
The second names the task, length, audience, tone and goal.
2. Give context the model doesn't have
The model doesn't know your business, your users or your codebase. Tell it the relevant parts: who it's for, what's been tried, what the constraints are. Explaining why helps too — "keep it under 160 characters because it's an SMS" leads to better choices than "keep it short".
3. Show examples (few-shot prompting)
If you want a particular format or style, show two or three examples. This is called few-shot prompting, and it's often more effective than describing the format in words.
Classify each support message as billing, bug or feature_request.
Message: "I was charged twice this month" → billing
Message: "The export button does nothing" → bug
Message: "Could you add dark mode?" → feature_request
Message: "My invoice shows the wrong VAT number" →
Vary your examples so the model doesn't copy one too closely.
4. Use structure
Separate instructions from data. Headings or XML-style tags work well with most models:
<instructions>
Summarise the customer email below in two bullet points.
</instructions>
<email>
...
</email>
This also helps with safety: the model can tell your instructions apart from user-supplied text.
5. Ask for a specific output format
"Reply in JSON with keys category and confidence" is easier to use in code than free text. For apps, use the model API's structured output feature, which guarantees valid JSON. (Structured output from LLMs)
6. Let it think on hard problems
For reasoning, maths or multi-step tasks, asking the model to work through the problem before answering improves accuracy. Many current models have a built-in thinking or reasoning mode that does this for you. (What is a reasoning model?)
7. Give it a role — briefly
"You are a senior Postgres DBA reviewing a migration" helps set expertise and tone. It's a small boost, not magic.
8. Test, don't guess
For anything that runs in an app, collect 20–50 real example inputs, run your prompt against them, and check the outputs. Change one thing at a time. A prompt that works on the three examples you thought of often fails on the fourth. (Evaluating LLM outputs)
What doesn't help much
- Shouting. "YOU MUST ALWAYS…" in capitals tends to make modern models overdo it.
- Long lists of "don't"s. Say what to do instead.
- Magic phrases copied from social media. Clear instructions beat tricks.
Prompting for coding tools
The same rules apply to AI coding assistants: name the file, the change, the constraints, and how to verify it. (How to write good prompts for AI coding tools)
Prompt engineering vs context engineering
As AI tools became agents that read files and use tools, the focus shifted from the wording of one prompt to managing everything the model sees: instruction files, retrieved documents, tool results, conversation history. That broader job is called context engineering. (Context engineering for coding agents)
The summary
- Be specific: task, audience, format, constraints.
- Provide context and the reasons behind instructions.
- Show examples for format and style.
- Separate instructions from data; ask for structured output.
- Test against real inputs.
EasySpawn gives you a persistent server with Claude Code built in, so you can build, test and run the AI features in your app in one place. See how it works or join the waitlist.
Related: What Is a System Prompt? · What Is an LLM? · LLM Temperature Explained · How to Write Good Prompts for AI Coding Tools
Keep reading
Why Does AI Hallucinate? And How to Reduce It in Your App
AI models sometimes state false things with complete confidence. Why it happens — they predict plausible text rather than look up facts — the kinds of hallucination you'll meet in coding and apps, and practical ways to reduce it: grounding, tools, structure, checks and room to say 'I don't know'.
MCP vs API: What's the Difference, and Do You Need Both?
An API is how programs talk to a service. MCP (Model Context Protocol) is a standard way for AI tools to discover and use those services. How they relate, why MCP servers usually wrap APIs, when to use each, and what MCP adds and costs.