All resources
AI Basics
26 August 20263 min readSritam Dash

Prompt Engineering 101: Getting Useful Answers from AI

Role, context, constraints, and examples โ€” four prompt engineering levers that dramatically improve AI output, with a clear before and after example.

Prompting is a real engineering skill

Prompt engineering is often described as voodoo, but it is much closer to writing a very clear specification. The model is a conditional next-token predictor working only with the context you gave it, which means the quality of your output is bounded by the quality of your input. A vague prompt cannot produce a precise answer.

The four levers

  • Role โ€” "Act as a senior code reviewer" frames the style and the level of detail the model should use.
  • Context โ€” give the model everything relevant: the code, the priorities, the constraints, the audience.
  • Constraints โ€” say what to avoid and what shape you want ("no explanations, only a diff", "under 200 words", "reply in JSON").
  • Examples โ€” show one or two ideal outputs. Concrete examples reliably beat vague adjectives like "make it professional".

A useful fifth lever is format specification: stating exactly how you want the response structured removes a whole class of failures where the content is right but the shape is wrong to parse.

A before/after example

Weak prompt: "Fix this code."

Stronger prompt: "Act as a senior Python reviewer. Here is the function and its failing test. Fix the bug, explain the root cause in two sentences, and do not change the public API."

The second prompt is better not because of any special words, but because it removes ambiguity. The model knows its role, has the failing test, knows how much explanation you want, and knows a hard boundary it must not cross.

Putting the most important thing last

This follows directly from how attention works. The tokens nearest the end of the prompt are the freshest and most strongly weighted when the model generates its response. When a prompt has many competing requirements, restate the critical one as the final line. If a constraint keeps getting violated, moving it to the end is often the cheapest fix.

Iterate like a scientist

Treat each prompt as an experiment. Change one lever at a time, record what improves, and keep the winning examples as templates you reuse.

The habit that separates people who are good at this is keeping a small prompt library: a folder of prompts that worked, each with a note on what problem it solves. Teams that build one stop re-solving solved problems, and you get the same benefit as a solo learner.

Know when prompting is not enough

Prompting improves behaviour on the cases you anticipated. It cannot reliably fix a model that lacks knowledge it does not have, cannot make a model reliably count characters, and cannot guarantee a factual answer it has no access to. When you hit those walls, the fix is a different tool โ€” grounding the model with RAG, constraining its output with a schema, or calling actual code for anything that needs real computation.

Knowing which wall you are hitting is the difference between tuning a prompt for a week and switching approach in a day.

Go deeper

Related reading