AI engineering glossary · Prompt context engineering

What is prompt engineering?

Prompt engineering: The practice of designing and refining the text sent to a language model so it gives reliable, useful answers without changing the model's weights. It covers wording, examples, structure, and testing variations. It is the cheapest way to improve behaviour before trying retrieval or fine-tuning.

Level: beginnerTopic: Prompt context engineering

Prompt engineering: an example

A team tries three versions of a resume-screening prompt on 50 sample resumes and keeps the one that matches recruiter decisions most often.

Prompt engineering in Python

A short example you can run (Python 3.11). The output below is what it really prints.

def build_prompt(task, examples, text):
    shots = "\n".join(f"Input: {i}\nLabel: {o}" for i, o in examples)
    return f"{task}\n\n{shots}\n\nInput: {text}\nLabel:"

prompt = build_prompt(
    "Classify each support message as BILLING, BUG or OTHER. Reply with one word.",
    [("I was charged twice", "BILLING"), ("The app crashes on login", "BUG")],
    "My invoice shows the wrong GST number",
)
print(prompt)

Output

Classify each support message as BILLING, BUG or OTHER. Reply with one word.

Input: I was charged twice
Label: BILLING
Input: The app crashes on login
Label: BUG

Input: My invoice shows the wrong GST number
Label:

Related terms

More Prompt context engineering terms

Where you learn it

Prompt engineering is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.