Prompt engineering
Designing the instructions, examples, and context a model sees so it does the job reliably.
Prompt engineering is the work of shaping what a model sees, the instructions, examples, retrieved context, and output format, so that it does a task reliably. It changes no weights. Everything it achieves happens inside a single request, which makes it the cheapest and fastest lever you have, and the first one to try before retrieval or fine-tuning.
Good prompts read like a clear brief to a capable colleague who has no background. State the goal, the audience, the constraints, and what a good answer looks like. Put stable instructions first and variable content last, both because it reads better and because it lets prompt caching reuse the shared prefix. Separate instructions from data with clear delimiters so the model can tell what to do from what to read.
Treat prompts as code. Keep them in version control, give them names and versions, and test changes against a fixed set of real inputs before you ship them. A change that fixes one example often breaks three others, and you only find out if you measure. Log which prompt version produced each answer so you can trace regressions.
Prompting has limits. It cannot give a model knowledge it lacks, which is the job of retrieval, and it cannot enforce a security boundary, which is the job of the code around the model. When a prompt grows into pages of special cases, that is usually a sign the task should be split into steps, backed by retrieval, or checked by code.
System prompt
High-priority instructions that frame a whole conversation, such as the model's role, rules, and constraints.
A system prompt is the set of instructions placed ahead of the conversation that frames every turn: the assistant's role, the rules it should follow, the tools it has, and the format of its answers. Chat models are trained to give it more weight than user messages, so it is the natural place for stable product behavior.
That priority is a learned habit, not an enforced boundary. Determined or cleverly crafted text in a user message or a retrieved document can sometimes override it, and a model may reveal its system prompt if asked the right way. Keep secrets out of it, and enforce anything that truly matters, such as permissions, spending limits, or data access, in the code around the model.
Few-shot prompting
Putting a few worked input and output examples in the prompt so the model copies the pattern.
Few-shot prompting places a handful of worked examples of inputs and desired outputs directly in the prompt so the model follows the pattern. No weights change; the model picks up the task from context, an ability called in-context learning. The effect lasts only as long as the examples are in the prompt.
Examples are often clearer than instructions, especially for formats, labels, and tone. They also teach things you did not intend: the model may copy the examples' length, phrasing, or topic, and the order of examples can bias results. Choose examples that vary along the dimensions that matter, include a tricky case or two, and check whether a clear instruction alone would do just as well.
Chain-of-thought
Having a model write out intermediate reasoning steps before its final answer.
Chain-of-thought is having a model write out intermediate reasoning before giving its final answer. Because the model generates one token at a time, each written step becomes context for the next, giving it room to work through multi-step problems such as math, logic, and planning that it would get wrong in a single leap.
The cost is more output tokens, which means more latency and money, and it adds little for simple lookups or classification. Many current models are trained to reason this way on their own before answering, sometimes in a hidden reasoning channel, and expose a setting for how much effort to spend. Written reasoning is not a faithful window into how the model reached its answer, so judge the answer itself, not how convincing the steps look.
Constrained decoding
Forcing model output to fit a format, such as a JSON schema, by blocking tokens that would break it.
Constrained decoding forces a model's output to match a format by blocking, at each step, any token that would break it. The format is usually a JSON schema, a grammar, or a regular expression. Before each token is chosen, tokens that cannot lead to valid output get zero probability, so the result is guaranteed to parse.
It is far more reliable than asking for JSON in the prompt, and it is what structured output modes in model APIs use. It guarantees shape, not truth: fields can still hold wrong values, and a tight schema can push the model into awkward answers when the right response does not fit. Keep validating the result in your own code, and leave an explicit way for the model to say it cannot answer.