English · IndiaLog in
Rackwave Technologies
Request quote Free consultation
AIUpdated 25 Nov 2026

What Is Prompt Engineering? Techniques and Best Practices

Prompt engineering explained: structure, techniques, testing and production practice.

Written by Emma Johansson
  • Published25 Nov 2026
  • Read time6 min
  • Length1,299 words
Share this guide

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

Diagram of prompt structure from role to task to context to examples to output format
Figure 1. A strong prompt states the role, task, context, examples and the format of the answer.
PartPurposeExample
RoleSets perspective and toneYou are a careful financial analyst
TaskStates exactly what to doSummarise the contract risks in five bullets
ContextGives the facts neededThe contract text, the audience, the date
ConstraintsLimits scope and styleUse only the text provided, no legal advice
ExamplesShows the pattern wantedTwo sample inputs with ideal outputs
Output formatMakes results usableReturn JSON with keys risk, severity, clause
Fallback ruleHandles missing informationIf the answer is not in the text, say so

Core prompting techniques

TechniqueWhat it isWhen to use
Zero shotAsk directly with clear instructionsSimple, common tasks
Few shotInclude several worked examplesConsistent format or unusual tasks
Step by step reasoningAsk the model to work through the problem before answeringMaths, logic and multi-step analysis
Role promptingAssign a role or audienceTone and domain framing
Structured outputRequire JSON or a fixed templateFeeding results into software
Prompt chainingSplit a job into several smaller promptsComplex workflows and easier debugging
Self reviewAsk the model to check its own answer against criteriaReducing errors in drafts

How to write and improve a prompt

  1. Define success. Write down what a good answer looks like and how you will judge it.
  2. Write a clear first version. State the task, audience and format plainly. Avoid vague words such as good or short and give numbers instead.
  3. Add context and examples. Provide the facts the model needs and one to three examples of ideal output.
  4. Set boundaries. Tell the model what to avoid and what to do when information is missing.
  5. Test on varied inputs. Include easy, hard and unusual cases, not just the example you wrote the prompt for.
  6. Change one thing at a time. Edit a single element, re-run the tests and keep the change only if scores improve.
  7. Version and document. Store prompts with change notes so others can reuse and audit them.

Weak and strong prompts compared

Weak promptWhy it failsStronger version
Summarise thisNo audience, length or focusSummarise this report for a board member in five bullets, focusing on cost and risk
Write a good emailVague and no contextWrite a polite 120 word email asking a customer to confirm delivery by Friday
Is this contract OK?No criteriaList clauses that differ from our standard terms, quoting each one
Fix my codeNo detailThis 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

TermMeaning
PromptThe instructions and context given to a model
Few shotGiving worked examples inside the prompt
Prompt chainingSplitting a task into several linked prompts
Prompt injectionMalicious text that tries to override instructions
System promptFixed 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.

Was this guide helpful?Your answer helps us decide what to improve. It is not linked to you.

#what is prompt engineering#prompt engineering techniques#few shot prompting#prompt best practices#prompt injection

About the author

Emma Johansson

Ecommerce & Lifecycle Marketing Consultant

Emma specializes in Klaviyo implementations for DTC and ecommerce brands, with particular depth in flow strategy and the data hygiene work that actually determines whether segmentation performs well.

Ecommerce & Lifecycle Marketing (Klaviyo)

Ready to put AI and data to work?

Book a free consultation and leave with a plan, not a pitch.

Get a free consultationRequest quote