Indexly
AI & LLMsUpdated May 6, 2026

Prompt engineering

Definition

Prompt engineering is the practice of designing and refining the inputs given to an AI model to produce precise, high-quality, and reliable outputs. It covers wording, structure, examples, context, and constraints — shaping how a model interprets a request without changing the model itself. Effective prompting is often the cheapest and fastest way to improve results.

How it works

Prompt engineering works by giving a model the context, structure, and constraints it needs to interpret a request the way you intend. Core techniques include being explicit about the task and desired format, providing relevant context, assigning a role, and specifying constraints such as length or tone.

Several patterns recur. Few-shot prompting includes example input-output pairs so the model infers the pattern. Chain-of-thought prompting asks the model to reason step by step before answering, which improves accuracy on multi-step problems. Structured prompts separate instructions, context, and data clearly, and request output in a defined format such as JSON to make responses easier to use programmatically.

Prompting is iterative. You draft a prompt, test it against varied inputs, observe failures, and refine. Because model behavior is probabilistic, robust prompts are tested across many cases rather than tuned to a single lucky example — and prompts that work well on one model may need adjustment on another.

Prompting vs fine-tuning and RAG

Prompt engineering, fine-tuning, and retrieval-augmented generation are complementary levers for shaping model output. Prompting is the fastest and cheapest: it requires no training and can be changed instantly, but its control is bounded by what fits in the context window and the model's existing capabilities.

Fine-tuning bakes consistent behavior or format into the model's weights, useful for high-volume narrow tasks. Retrieval supplies current or proprietary facts at inference time. In practice teams start with prompting, reach for retrieval when they need fresh information, and fine-tune only when prompting cannot deliver the consistency they require.

Why it matters

The same model can produce mediocre or excellent results depending almost entirely on how it is prompted. Because prompting needs no training and takes effect immediately, it is usually the first and highest-leverage place to improve an AI feature's quality, cost, and reliability.

Prompt engineering also underpins more advanced systems. Agents, tool use, and structured pipelines all depend on carefully constructed prompts to behave predictably. As models grow more capable, the emphasis shifts from clever phrasing toward providing the right context and clear instructions — sometimes described as context engineering.

Frequently asked questions

What is few-shot prompting?

Few-shot prompting includes a handful of example input-output pairs in the prompt so the model infers the desired pattern and format. It often improves accuracy and consistency on tasks where a clear example communicates intent better than instructions alone, at the cost of using more of the context window.

What is chain-of-thought prompting?

Chain-of-thought prompting asks a model to reason step by step before giving a final answer. Working through intermediate steps improves accuracy on multi-step reasoning, math, and logic problems. Many modern reasoning models do this internally, reducing the need to request it explicitly.

When should I fine-tune instead of refining prompts?

Refine prompts first — it is faster, cheaper, and reversible. Consider fine-tuning when you need highly consistent style or format that prompting cannot reliably enforce, or when shortening prompts on a high-volume task would cut cost and latency. For fresh facts, use retrieval rather than either.

Do prompts transfer between different models?

Often partially, but not perfectly. Models differ in how they interpret instructions, handle formatting, and respond to reasoning cues, so a prompt tuned for one model may need adjustment on another. Re-testing prompts when you switch models is good practice.

Context engineering

Context engineering is the discipline of assembling the right information, instructions, tools, and memory into a language model's context window so it produces accurate, grounded outputs. It broadens prompt engineering beyond wording to the whole question of what gets retrieved, included, ordered, and excluded at inference time.

Few-shot learning

Few-shot learning is the ability of a model to learn a new task from just a handful of examples, typically two to ten, provided directly in the prompt rather than through retraining. By showing the model a few input-output pairs, you steer it toward the desired format and behavior. It is a core technique in prompt engineering with modern language models.

Chain of thought (CoT)

Chain of thought is a prompting technique that improves a model's reasoning by encouraging it to work through a problem step by step before giving a final answer. Making intermediate reasoning explicit helps models handle multi-step math, logic, and planning tasks more reliably. Once a hand-written prompting trick, chain-of-thought reasoning is now built directly into reasoning models that think before they respond.

AI fine-tuning

AI fine-tuning is the process of taking a pre-trained model and training it further on a smaller, specialized dataset so it adapts to a specific task, domain, tone, or format. It adjusts the model's existing weights rather than training from scratch, producing outputs that better match a brand's requirements or a narrow use case at lower cost than full training.

Retrieval-augmented generation (RAG)

Retrieval-augmented generation (RAG) is an AI architecture that gives a large language model real-time access to external documents at query time — retrieving relevant passages from a vector database or search index and inserting them into the model's context before it generates a response. RAG is the foundation of modern AI search and the most effective technique for reducing hallucination.

Context window

A context window is the maximum amount of text, measured in tokens, that a language model can consider in a single interaction — including the prompt, retrieved documents, conversation history, and the model's own output. Frontier models in early 2026 reach context windows of roughly a million tokens, enabling long documents and rich grounding.