Prompt Engineering
The practice of designing prompts to reliably get the desired output from a language model.
What Is Prompt Engineering
Prompt engineering is the practice of designing and refining the text sent to a large language model in order to reliably produce a desired output. It covers how instructions are phrased, what examples or context are included, and how the request is structured, and it applies to system prompts, user prompts, and any templates an application generates automatically.
Common Techniques
- Clear instructions: stating the task, desired format, and constraints explicitly rather than relying on the model to infer them.
- Few-shot examples: including sample inputs and outputs in the prompt so the model can infer the expected pattern.
- Chain-of-thought prompting: asking the model to reason step by step before giving a final answer, which can improve accuracy on tasks involving logic or multi-step calculation.
- Role assignment: instructing the model to act as a particular kind of expert or assistant to steer its tone and focus.
- Output constraints: specifying a required format, such as a JSON schema, so downstream code can parse the response reliably.
Why It Matters
The same underlying model can produce noticeably different results depending on how a task is framed, so prompt engineering is often the fastest and cheapest way to improve output quality, well before considering fine-tuning or switching models. It is especially important in production systems where output has to be consistent and machine-readable rather than merely readable by a person. A task with a schema-validated output contract, for example, depends on prompt engineering to reliably produce well-formed JSON that matches the expected structure.
Prompt Engineering vs Fine-Tuning
Prompt engineering changes what is sent to a model at request time and requires no retraining, so it can be iterated on quickly and applied instantly across an application. Fine-tuning, in contrast, changes the model's underlying parameters through additional training and is better suited to teaching a model a new skill, style, or domain that cannot be conveyed through instructions alone. Many production systems use prompt engineering as the first line of tuning and reserve fine-tuning for cases where prompting has clear limits.
Limitations
Prompt engineering cannot add knowledge the model was never trained on, and results can be sensitive to small wording changes, which makes systematic testing important. Techniques that work well with one model or version do not always transfer cleanly to another, so prompts built for a production system generally need to be re-tested whenever the underlying model changes.