Level 03 · Foundations
Prompt Engineering
This level teaches you how to write instructions a model can follow. You will split a prompt into parts, add examples when the shape is unfamiliar, ask for reasoning only when the task needs it, and lock the output when a program must read it. An AI engineer needs this because the wording is part of the product, and a vague sentence becomes a bug a person can see long before stored context matters.
Assumes You can already send text to a model from a program or a chat window and read the text that comes back. · 11 study sessions · 8 modules
Ship it
Optimize a Real Prompt
You will take one small task a model can do, such as labeling a short email or pulling a date out of a sentence, and you will improve the instructions until the answers are steady. Freeze a set of examples first, try more than one wording, and keep every raw reply from a free chat window. You do not need a paid API key.
The point is to choose with a score table, not with a single reply that sounded nice. You are finished when you can point at the version you would keep and say which cases it still gets wrong.
1. Choosing a realistic task
1. Pick one task you can judge by eye: a short-text label, a few extracted fields, a reply grounded in a paragraph you wrote, or a narrow helper with a written scope.
2. Write one ideal input and one ideal output at the top of TASK.md so the target is concrete.
3. Do not expand it into an open general chatbot. If the task needs a web search or a secret key, pick a smaller task.
4. You are done when TASK.md states the task in one paragraph and shows one ideal pair.2. A test set and competing prompt versions
1. Build a fixed set of at least twelve inputs in cases.jsonl. Include ordinary cases, edges, and two hostile or malformed ones.
2. Write at least three prompt versions that differ in structure, examples, or system rules. Save them as v1.md, v2.md, and v3.md.
3. Run every version on every row in a free chat. Save the raw outputs next to the case id. Work in batches if the chat limits length, but do not drop rows.
4. You are done when a folder of outputs has three versions times twelve cases, and you could rescore them without sending a new prompt.3. Correctness
1. Write the correctness rubric in RUBRIC.md before you reread the model text. Say what makes a label or a field right.
2. Score each saved output against the source. Compute a correctness rate per prompt version.
3. If two versions tie, note which errors would actually mislead a person.
4. You are done when the rate for each version is a fraction, such as 9/12, and the rubric file is older in spirit than the scores, meaning you did not change the rubric to flatter a version.4. Instruction following
1. Add a second score for instruction following: did the reply obey the rules you wrote, including required questions, refusals, and facts it must not invent.
2. A fluent answer in the wrong shape fails this axis even when the facts are close.
3. Mark pass or fail per case with a one-line reason in follow.md.
4. You are done when every scored case has a reason and at least one fail is included if any version broke a rule.5. Output-format adherence
1. Score the mechanical shape separately from truth: exact labels, JSON keys, length caps, or table columns.
2. Count fenced JSON and extra preambles as misses.
3. If a version cannot hold the format, write whether a schema or a json.loads check would be the real fix rather than more wording.
4. You are done when format.md has a miss count per version and one sentence on schema versus wording.6. Consistency
1. Run each version twice on the same five cases. If the chat has a temperature control, set the value you would actually ship, or 0 if labels should not move.
2. Count how often the label or the key fields change between the two runs.
3. Prefer the version whose decisions stay put when the input stays put. If every version flaps, tighten the output rule and rescore before rewriting the whole prose.
4. You are done when a table shows two runs for five cases and names the steadier version.7. Token usage
1. For each version, estimate size. Count words in the system text, the examples, and a typical reply if the chat does not show tokens.
2. Write the average input size and output size per case.
3. Drop a version that spends far more words for a tiny score gain, unless that gain fixes a severe error. Note which block accounts for the extra words.
4. You are done when tokens.md, or words.md, has those averages and names the expensive block.8. Latency & cost
1. Time one case per version with a watch. Write the seconds down as latency.
2. Estimate cost as low, medium, or high from the word counts. If you looked up a public price, cite it. Do not invent a dollar amount you did not compute.
3. Include a retry only if you actually sent the prompt again.
4. You are done when the table has latency and a cost note for each version, and a slower version is justified by a quality score or marked as not worth it.9. Choosing on measurement, not intuition
1. Choose the prompt you will keep from the score table. Write the tradeoff you accepted, such as a lower word count with one remaining miss.
2. Save the winning prompt id next to the test set in DECISION.md so someone else can reproduce the result.
3. Keep the losing versions in the folder as a record of what you tried.
4. You are done when DECISION.md names the winner, the tradeoff, and one case the winner still gets wrong.