What is prompt engineering? It is the practice of designing and refining the instructions, context and examples given to a generative AI model so that it produces accurate, useful and consistent output. A prompt is more than a question. It can include a role, the task, background information, constraints, examples and a required output format. Good prompt engineering turns a general purpose language model into a dependable component of a business process. This guide explains the core techniques, how to structure prompts, how to test them and how to manage prompts in production.
Short answer: Prompt engineering means writing clear, specific and well structured instructions for an AI model, supplying the right context and examples, and testing the results systematically. Small changes in wording can change quality a lot, so prompts should be treated like code: versioned, evaluated and improved.
What is prompt engineering?
Prompt engineering applies to any large language model and is described in the prompt engineering article on Wikipedia. It sits alongside retrieval augmented generation and fine tuning as one of the main ways to shape model behaviour, and it is usually the cheapest and fastest to try first.
The parts of a good prompt

| Part | Purpose | Example |
|---|---|---|
| Role | Sets perspective and tone | You are a careful financial analyst |
| Task | States exactly what to do | Summarise the contract risks in five bullets |
| Context | Gives the facts needed | The contract text, the audience, the date |
| Constraints | Limits scope and style | Use only the text provided, no legal advice |
| Examples | Shows the pattern wanted | Two sample inputs with ideal outputs |
| Output format | Makes results usable | Return JSON with keys risk, severity, clause |
| Fallback rule | Handles missing information | If the answer is not in the text, say so |
Core prompting techniques
| Technique | What it is | When to use |
|---|---|---|
| Zero shot | Ask directly with clear instructions | Simple, common tasks |
| Few shot | Include several worked examples | Consistent format or unusual tasks |
| Step by step reasoning | Ask the model to work through the problem before answering | Maths, logic and multi-step analysis |
| Role prompting | Assign a role or audience | Tone and domain framing |
| Structured output | Require JSON or a fixed template | Feeding results into software |
| Prompt chaining | Split a job into several smaller prompts | Complex workflows and easier debugging |
| Self review | Ask the model to check its own answer against criteria | Reducing errors in drafts |
How to write and improve a prompt
- Define success. Write down what a good answer looks like and how you will judge it.
- Write a clear first version. State the task, audience and format plainly. Avoid vague words such as good or short and give numbers instead.
- Add context and examples. Provide the facts the model needs and one to three examples of ideal output.
- Set boundaries. Tell the model what to avoid and what to do when information is missing.
- Test on varied inputs. Include easy, hard and unusual cases, not just the example you wrote the prompt for.
- Change one thing at a time. Edit a single element, re-run the tests and keep the change only if scores improve.
- Version and document. Store prompts with change notes so others can reuse and audit them.
Weak and strong prompts compared
| Weak prompt | Why it fails | Stronger version |
|---|---|---|
| Summarise this | No audience, length or focus | Summarise this report for a board member in five bullets, focusing on cost and risk |
| Write a good email | Vague and no context | Write a polite 120 word email asking a customer to confirm delivery by Friday |
| Is this contract OK? | No criteria | List clauses that differ from our standard terms, quoting each one |
| Fix my code | No detail | This function returns null for empty lists. Explain the cause and give a corrected version with a test |
Prompting in production
- Keep prompts in version control with owners and review, like any other code.
- Build an evaluation set and run it automatically when a prompt or model changes.
- Validate and sanitise user input, and protect against prompt injection by limiting what the model is allowed to do.
- Separate fixed instructions from user supplied text so that users cannot overwrite the rules.
- Log inputs, outputs, cost and latency for monitoring. See what is MLOps.
- Use human review for decisions that affect customers, money or safety.
Common prompt engineering mistakes
- Writing long, tangled prompts that mix several tasks.
- Testing on a handful of cherry picked examples.
- Assuming a prompt that works on one model will work unchanged on another.
- Putting secrets or customer data in prompts without controls.
- Skipping the fallback rule, so the model guesses when it should decline.
- Never revisiting prompts as data, products and models change.
Our AI and machine learning service helps teams design, test and operate prompts and AI workflows, and our API development service connects them to business systems. For a wider view of safe adoption, read what is responsible AI.
A worked example: classifying support tickets
A support team wants every incoming ticket tagged with a category and urgency. The first prompt, classify this ticket, gives inconsistent labels. The team rewrites it with a role, a fixed list of eight categories with one line definitions, three examples that include an ambiguous case, a rule to choose other when unsure and a requirement to return JSON with category, urgency and a short reason.
They test the prompt on 300 historical tickets labelled by agents. Accuracy rises from 71 percent to 89 percent. Errors cluster around billing disputes, so they add two more examples and a clearer definition, and accuracy reaches 93 percent. The prompt is stored in version control, the 300 tickets become the regression test, and a weekly sample of live results is reviewed by a team lead. The gain came from specificity, examples and testing rather than from any clever phrase.
Prompt engineering and the wider AI stack
Prompts do not work in isolation. For answers that depend on company knowledge, retrieval supplies the facts and the prompt tells the model how to use them. For tasks that require actions, the prompt defines which tools may be called and what to do when a tool fails. For high volume tasks, smaller tuned models can follow a fixed prompt cheaply. As systems grow, teams often move from single prompts to workflows of several prompts with checks between steps, which are easier to test and debug than one very large instruction.
Prompting for different business tasks
Different tasks reward different prompt designs. Extraction tasks, such as pulling dates and amounts from invoices, need a strict output schema and a rule for missing fields. Drafting tasks need audience, tone and length, and benefit from a short style guide or a sample of approved writing. Analysis tasks need the data supplied in full, a request to show the reasoning and a request to flag assumptions. Classification tasks need a closed list of labels with definitions and an explicit option for unclear cases.
Teams that document these patterns in a shared library save time and improve consistency. See also what is generative AI and what is natural language processing for background on how models handle language.
Key takeaways
- Prompt engineering is the discipline of writing, testing and managing instructions for AI models.
- Strong prompts state role, task, context, constraints, examples and output format.
- Few shot examples, structured output and prompt chaining improve consistency.
- Treat prompts like code: version, evaluate and review them.
- Defend against prompt injection and keep humans in the loop for high stakes use.
Quick glossary
| Term | Meaning |
|---|---|
| Prompt | The instructions and context given to a model |
| Few shot | Giving worked examples inside the prompt |
| Prompt chaining | Splitting a task into several linked prompts |
| Prompt injection | Malicious text that tries to override instructions |
| System prompt | Fixed instructions that set model behaviour |
Read next: What Is Fine-Tuning? Methods, Data and Costs · What Is Feature Engineering? Techniques and Workflow · What Is Explainable AI? Methods, SHAP and LIME
Frequently asked questions
What is prompt engineering in simple terms?
It is writing clear and specific instructions, with the right context and examples, so an AI model gives accurate and useful answers.
Is prompt engineering a real skill?
Yes. Quality, cost and safety depend on how prompts are designed, tested and maintained, which is why many teams treat it as part of software and data work.
What is few shot prompting?
Few shot prompting includes a small number of example inputs and ideal outputs in the prompt, so the model copies the pattern and format.
What is the difference between prompt engineering and fine tuning?
Prompt engineering changes the instructions given at run time. Fine tuning changes the model itself through extra training, which is slower and costlier.
How long should a prompt be?
As long as needed to be clear, and no longer. Focused prompts with examples usually beat very long, mixed ones.
How do I test a prompt?
Create a set of realistic inputs with expected outputs, score the results, and re-run the set whenever the prompt or model changes.
What is prompt injection?
It is an attack where text in the input tries to make the model ignore its instructions. Limit permissions, separate instructions from user text and validate outputs.
Will prompts work the same on every model?
Not always. Different models respond differently, so re-test prompts when you switch or upgrade models.
