Glossary

Prompt engineering

The practice of writing and testing the instructions, examples and structure given to a language model so it produces the output you need.

Prompt engineering is the practice of designing, testing and refining the text a language model receives, its instructions, examples, constraints and output format, so that it reliably produces the result you need. A good prompt states the task plainly, supplies the information the model lacks, shows what a good answer looks like and says what to do when the answer is unknown. For single requests that is most of the work. For agents that run many steps over long sessions, the instructions become a small and fairly stable part of what the model sees, and the larger job is choosing which retrieved documents, memories and tool results go into each call, which is usually called context engineering.

What a prompt contains

A modern prompt is rarely one sentence. Through a chat API it usually has several parts. The system prompt sets the role, rules and output format for the whole conversation. Reference material, such as retrieved documents or facts about the user, gives the model information it would not otherwise have. Examples show the format and judgement you want. The user’s message carries the request itself. For agents there are also tool definitions and the results of earlier tool calls. Every part costs tokens and competes for the model’s attention inside a finite context window.

Prompt engineering is the discipline of deciding what goes into each part and in what order, then testing whether the output improves. It is closer to writing a specification than to finding magic words. Phrasing tricks that once helped weaker models matter much less with current ones; clarity, structure and the right information matter more.

Core techniques

Most of the field reduces to a handful of techniques, used in combination.

Technique

What it does

When it helps

Clear instructions

States the task, audience, constraints and output format

Always; the largest single gain

Zero-shot prompting

Asks for the task with no examples

Common tasks the model already does well

Few-shot prompting

Includes worked examples of input and output

Unusual formats, judgement calls, edge cases

Chain of thought

Asks the model to reason step by step before answering

Multi-step reasoning, arithmetic, planning

Structured output

Requires JSON or another fixed schema

Outputs that code will parse

Prompt chaining

Splits a task into several smaller prompts

Long tasks with distinct stages

Grounding instructions

Tells the model to answer only from supplied sources

Factual answers over documents

Write clear, specific instructions

Say what the task is, who the output is for, what to include and leave out, and what format to use. State constraints positively where possible: “reply in under 80 words” works better than a list of things to avoid. Put the most important instruction where it is hard to miss, and avoid contradictions between the system prompt and later messages. Delimit reference material clearly, for example with headed sections or tags, so the model can tell instructions from data. A prompt template keeps this structure consistent while variables change per request.

Show examples

Zero-shot prompting is enough for many tasks. When the format is unusual or the task involves judgement, few-shot prompting adds two to five worked examples, which the model generalises from through in-context learning. Choose examples that cover the hard cases, keep them consistent with each other, and vary them enough that the model does not copy surface details such as length or wording.

Ask for reasoning where it helps

Chain-of-thought prompting asks the model to work through a problem before giving its answer, which improves accuracy on multi-step tasks. Reasoning models do this internally, so explicit instructions to think step by step add less with them. Either way, the reasoning text can contain errors of its own, so judge the final answer rather than trusting the explanation.

Constrain the output

If code will read the response, ask for structured output and enforce it with JSON mode or a JSON schema where the provider supports it. For agents, function calling is the structured interface: tool names, descriptions and argument schemas are part of the prompt, and writing them well is one of the most effective prompt changes you can make. Clear tool descriptions reduce wrong tool choices more than any instruction about which tool to use.

Break large tasks into steps

Prompt chaining splits a task into stages, such as extract, then classify, then draft, each with its own focused prompt. Each stage is easier to test and fix, and intermediate outputs can be checked before the next step runs. The cost is more calls and more latency, so chain only where a single prompt is unreliable.

Prompt engineering for agents

An AI agent calls the model many times in a loop, and each call’s prompt is assembled from parts that change: the conversation so far, tool results, retrieved documents and remembered facts. The system prompt and tool definitions stay roughly fixed; everything else grows. Three problems follow.

The first is length. A prompt that carries the whole session history grows with every turn, so the instructions written at the top become a shrinking share of what the model sees. Research on long inputs finds accuracy falling as inputs grow, the pattern called context rot, and dropping by more than 30 percent when the relevant passage sits in the middle, the lost in the middle effect. No wording in the system prompt fixes that.

The second is cost. A typical agent request might carry around 500 tokens of system prompt, several thousand tokens of history and a few thousand of retrieved chunks. Tuning the 500 tokens of instructions changes little about the bill; the history and chunks drive it. Prompt caching helps with the stable prefix and does nothing for the parts that change on every request.

The third is security. Anything placed in the prompt can carry instructions, including web pages, emails and documents the agent retrieves. Prompt injection and its indirect form exploit this. Clear delimiting of untrusted content helps, but it is not a complete defence, so agents also need guardrails, limited tool permissions and checks on actions with side effects. Jailbreaks are the user-side version of the same problem.

Prompt engineering and context engineering

These pressures are why many teams now talk about context engineering: designing the whole set of information the model receives on each call, including what to retrieve, what to remember, what to summarise and what to leave out. Prompt engineering is part of it, covering the instructions and examples. Context engineering adds the retrieval, memory and selection decisions that determine most of the tokens. Context engineering vs prompt engineering compares the two in detail.

In practice the split is useful for deciding where to spend effort. If the model has the right information and still answers in the wrong shape, it is a prompt problem. If it answers confidently from the wrong information, or misses a fact it was told three sessions ago, it is a context problem, and the fix lies in retrieval-augmented generation and agent memory. Confusing the two leads to long system prompts full of rules that try to compensate for missing facts, which tends to increase hallucination rather than reduce it.

Testing prompts

A prompt change is a code change and needs the same discipline. Keep prompts in version control, build a golden dataset of representative inputs with expected outputs, and run every change against it before release. Score format compliance automatically, and use an LLM as a judge or human review for quality, as part of a wider LLM evaluation setup. Test at the temperature you will run in production, run each case more than once to see variance, and re-test when you change model versions, since a prompt tuned for one model can behave differently on the next.

A worked example

A team builds a triage agent that reads incoming support emails and assigns a category, a priority and a short summary. The first prompt is two sentences and gets the category right on 78 percent of a 300-email test set. Adding a definition and one example for each of the eight categories lifts that to 88 percent. Requiring JSON output with an enum for the category removes the parsing failures. Moving the category definitions above the email text, and wrapping the email in clearly marked tags, stops the model treating instructions inside customer emails as its own.

The remaining errors are different in kind. Most involve customers whose history matters: a priority account, an issue already escalated last week, a customer who has asked for replies in French. Rewording does not help because the model has never been told those facts. The team adds a memory lookup for the sender and passes the three or four relevant facts into the prompt, and accuracy rises again while the prompt itself gets shorter. The figures are illustrative; the pattern of instruction fixes first and context fixes second is common.

Where Exabase fits

Exabase is the context layer around your prompts and does not write or tune them. Exabase Memory turns conversations into structured facts and returns the ones relevant to the current task, so an agent’s prompt can carry a few hundred tokens of current facts in place of a long history; the retrieving memories guide covers query expansion and reranking settings. Deep Search returns the specific passage that answers a question, with page numbers or timestamps, so the prompt holds evidence rather than a pile of loosely related chunks; see the searching resources guide. Workers take a plain-language prompt and a schedule and run it against a Base, which makes prompt clarity directly useful for maintenance jobs.

In an illustrative request, replacing raw history and top-K chunks with retrieved memories and precise passages cuts input from about 15,100 tokens to about 2,800, roughly 81 percent fewer. The reduce token costs page walks through it, the token cost calculator estimates it for your numbers, and the RAG accuracy page covers retrieval quality. The coding assistants use case shows the approach in a product, and the best AI context platforms roundup compares options.

FAQs

Is prompt engineering still relevant with newer models?

Yes, though its focus has shifted. Newer models need fewer phrasing tricks, but they still need clear instructions, the right information, good examples and a specified output format. For agents, the larger gains now come from managing context: what is retrieved and remembered for each call.

What is the difference between a system prompt and a user prompt?

The system prompt sets the model’s role, rules and format for the whole conversation and is written by the developer. The user prompt is each individual request. Models are trained to weight system instructions more heavily, though they can still be overridden by persuasive or injected text.

How long should a prompt be?

As long as the task needs and no longer. Include every instruction and fact the model needs, and cut rules that do not change the output in testing. Very long prompts cost more and can lower accuracy, so move reference material into retrieval and keep the fixed instructions concise.

Is prompt engineering better than fine-tuning?

Start with prompt engineering. It is faster, cheaper and easier to change. Fine-tuning is worth trying when well-tested prompts still give inconsistent format, style or tool use, or when you want a smaller model to match a larger one on a narrow task.

How do I stop a prompt from being overridden by user input?

Separate instructions from untrusted content with clear delimiters, tell the model to treat that content as data, and limit what the agent can do with tools. No prompt is fully resistant to injection, so validate outputs and require confirmation for actions with side effects.

What is the difference between prompt engineering and context engineering?

Prompt engineering covers the instructions and examples you write. Context engineering covers everything the model sees on each call, including retrieved documents, memories and tool results, and decides what to include or leave out. For agents, context engineering usually determines most of the tokens and most of the accuracy.

Related pages: Context engineering, Context engineering vs prompt engineering, System prompt, Few-shot prompting, Chain of thought, Prompt injection, Fine-tuning, Reduce token costs, How to cut token costs, Best AI context platforms, prompt template

Cut your token spend and give your agent precise context.

Get started in minutes.

Cut your token spend and give your agent precise context.

Get started in minutes.