Menu

Prompt Engineering: What It Is and How to Learn It

Prompt engineering is the practice of writing and testing the instructions you give an AI model so it produces the output you need. This guide explains why it works and maps every core technique.

Every prompt below is editable: change it, then open it in ChatGPT, Claude or another AI app.

Prompt engineering is the practice of writing, testing and refining the instructions you give an AI model so that it produces the output you need, reliably. It covers what you put in a prompt (the task, the context, examples, the input) and how you arrange it (order, format, separators). The term sounds technical, but most of it is careful writing plus checking the results.

This page is the index of Coddy's prompt engineering guide. It explains why the practice works, maps the core techniques to the pages that teach them, and shows the difference between a casual prompt and an engineered one.

Why prompt engineering works

A language model generates text by predicting what comes next, one small piece at a time, based on everything in front of it. It has no access to your intentions, your project or your previous chats unless that text is in its input. So the prompt is not a request to a mind that already understands you; it is the entire situation the model is responding to.

That has a direct consequence. Every question the prompt leaves open, the model tends to settle with the most typical choice: the most common language, the most common length, the most common audience. Sometimes the typical choice is what you wanted. When it is not, the fix is to close the question in the prompt. A good prompt narrows the range of plausible replies until most of what remains is useful.

Two more facts shape the craft. Replies are sampled, so the same prompt can produce different answers on different runs; a prompt is only good if it works most of the time, not once. And the model treats all text in the prompt as potentially meaningful, so a pasted email or a stray sentence can be read as an instruction unless you mark it clearly as material.

A casual prompt versus an engineered one

Both tabs ask for the same thing: sort customer reviews into positive and negative. Compare what each one gets back.

Are these reviews positive or negative? 1. The app is fast but it logged me out twice today. 2. Exactly what I needed for tracking my runs. 3. Support never answered my email.
Try it
Example replyReplies vary between models and runs.

Here's a breakdown:

  1. Mixed. The user likes the speed but is frustrated about being logged out.
  2. Positive. The app meets their needs for tracking runs.
  3. Negative. The user is unhappy that support didn't respond.

Overall, the feedback is mixed, with one positive, one negative and one mixed review.

The casual reply is a sensible answer for a person to read, but a program cannot use it: the labels are mixed in with explanations, a third category appeared that the question did not offer, and a summary was added at the end. The engineered prompt defines every label, fixes the output shape with an example, and wraps the reviews in tags so they are less likely to be confused with instructions. Run on a thousand reviews, it gives output a program can parse far more consistently, and when you need a guarantee, the API's structured output features and a validation step in your code close the rest of the gap.

The core techniques

Each technique below closes a different kind of gap between what you meant and what the model received. Most real prompts combine several.

TechniqueWhat it doesReach for it when
Zero-shot promptingGives an instruction with no examplesThe task is common and clearly described
Few-shot promptingShows a few input and output examplesThe format or judgment is easier to show than to describe
Chain-of-thought promptingAsks for the reasoning before the answerThe problem has several steps, like math or logic
Role promptingSets whose voice and standards to useAudience and level matter
Structured outputFixes the answer to JSON, a table or a templateA program or a spreadsheet reads the result
Delimiters and XML tagsSeparates instructions from pasted materialThe prompt contains documents, code or user text
Prompt templatesTurns a good prompt into one with blanksYou repeat the same kind of request
Prompt chainingSplits a job into steps that feed each otherOne prompt tries to do too much
Self-consistencySamples several answers and takes the majorityA single reasoning path is unreliable
Tree of thoughtExplores and scores several lines of reasoningThe problem needs planning or search
ReActAlternates reasoning with tool callsThe model must look things up or take actions
Meta promptingHas the model write or improve a promptYou are stuck on how to phrase a prompt
Context engineeringDesigns everything the model sees, not only the instructionYou are building an app or agent around a model

If you are new, start with the parts of a single prompt in how to write a prompt, then few-shot prompting and structured output. Those three cover most everyday problems.

A prompt built for a program

Prompts written into software get run thousands of times on inputs nobody has seen yet, so they spell out more than a chat message would. The one below writes commit messages from a code diff. Switch parts off to see what each one protects against: without the examples the style drifts, and without the constraints the model may use types your team does not, such as perf or style.

Commit message from a diff
Fill in
Parts
You write git commit messages for a team that follows the Conventional Commits format.
Write a commit message for the diff below.
feat(cart): add quantity selector to cart items fix(api): return 404 instead of 500 for an unknown user id
First line: type(scope): summary, at most 60 characters, in the imperative mood. Then a blank line and up to three bullet points explaining why the change was made.
Use only these types: feat, fix, refactor, docs, test, chore. If the diff mixes unrelated changes, say so instead of writing a message.
function validatePassword(password) { - if (password.length > 8) { + if (password.length >= 8) { return null; } return 'Password must be at least 8 characters'; }
Try it
Example replyReplies vary between models and runs.
fix(auth): accept passwords of exactly 8 characters

- The check used > 8, so an 8-character password was rejected
- The rule now matches the error message, which says "at least 8"

How to learn prompt engineering

You learn it by running prompts and looking hard at what comes back. A practical route:

  1. Learn the parts of a prompt. Task, context, input, format and constraints. Most failures trace back to one of them missing.
  2. Pick a real task you repeat, such as summarizing tickets, explaining errors or drafting emails, and write a prompt for it.
  3. Collect five to ten test inputs, including awkward ones: an empty input, a very long one, one in another language.
  4. Change one thing at a time and rerun all the inputs. If you change three things and the output improves, you will not know which change helped. Iterating on prompts covers this loop in detail.
  5. Add techniques when a specific failure calls for them. Examples when the format drifts, step-by-step reasoning when multi-step answers are wrong, delimiters when pasted text leaks into the instructions.

The major model providers also publish prompting guides for their own models, and they are worth reading, since each one describes what that model family responds to best.

Is prompt engineering a job?

Some companies have hired for the title "prompt engineer", especially when chat models first became widely available. More often the skill is part of another job. Developers write prompts for the AI features they build, support teams write them for assistants that answer customers, and analysts and writers use them daily.

In teams that build AI products, the work has broadened. Choosing what goes into the model's input (retrieved documents, tool results, conversation history, memory) matters as much as the wording of the instruction, and that wider job is often called context engineering. Measuring whether a prompt works across many inputs, usually called evaluation, is the other half.

What changes with newer models

Early prompt engineering relied on tricks: magic phrases, elaborate personas, repeating an instruction several times. Current models follow plain instructions much better, and reasoning models already work through a problem internally before answering, so asking them to think step by step adds less than it used to.

What has not changed is the part that was never a trick. The model still cannot know your audience, your data, your constraints or what a good result looks like unless you say so. Clear specification is the durable skill, and it is the one this guide spends most of its pages on.

Frequently Asked Questions

What is prompt engineering in simple words?

Prompt engineering is writing the instructions for an AI model carefully enough that it gives you the answer you need, then testing and adjusting them until it does so reliably. It covers what you tell the model (the task, context and examples) and how you arrange it (order, format and separators).

Can I learn prompt engineering without coding?

Yes. The core skills, stating a task clearly, supplying context, giving examples and specifying the output format, all work in a chat app. Coding becomes useful when you want to run a prompt many times, test it against a set of inputs, or feed the output into a program.

How long does it take to learn prompt engineering?

The basics take an afternoon: the parts of a good prompt and a handful of techniques such as few-shot examples and structured output. Getting reliable results on a real task takes longer, because it comes from testing your prompt on many inputs and fixing the cases where it fails.

Is prompt engineering a real job?

Some companies have hired for titles like "prompt engineer", but more often the skill is part of another role: developers building AI features, writers, analysts and support teams. In teams that build AI products, it overlaps with evaluation work and with designing everything the model sees, which is now often called context engineering.

Is prompt engineering still useful with newer AI models?

Newer models need fewer tricks. They follow plain instructions better, and reasoning models work through problems without being told to think step by step. What stays useful is the part that was never a trick: stating the task, giving the model the facts it cannot know, and defining what a good answer looks like.

Coddy programming languages illustration

Learn to code with Coddy

GET STARTED