Contract
- Input: task description, target LLM, evaluation criteria.
- Output: prompt library + evaluation report + recommendation.
- Side effects: may call LLM APIs (cost, data privacy).
- Dependencies: LLM API access (OpenAI, Anthropic, local model server).
- Stop condition: best variant selected with evaluation evidence.
- Risk: medium — LLM outputs can be unreliable; requires validation; data privacy concerns.
- Boundary: evaluates and selects prompts; does not deploy to production without additional validation.
Prompt Engineering
Design LLM prompts that produce correct, consistent, and useful outputs — with evaluation, iteration, and failure-mode analysis.
Process
1. Frame the task
State exactly what the LLM should do:
- Information extraction / summarisation.
- Code generation / explanation.
- Reasoning / proof / analysis.
- Creative generation.
- Classification / labeling.
Completion criterion: task statement precise; success criteria defined.
2. Design the prompt
Structure with clear sections:
- System message: role and constraints (e.g. "You are a careful mathematician.").
- Context: background, relevant data, rules.
- Instruction: what to do; format of output.
- Examples: zero-shot, few-shot (2–5 examples with input/output pairs), chain-of-thought (show reasoning steps before answer).
- Constraints: length, tone, forbidden content.
- Output format: JSON, Markdown, list, single paragraph.
Completion criterion: prompt structure explicit; examples selected.
3. Evaluate variants
Test at least 3 variants (baseline, improved, best guess):
- Accuracy — correct vs reference answer.
- Consistency — same answer across 3 runs with same prompt (temperature 0 or low).
- Latency — time per call.
- Cost — tokens used (input + output).
- Failure modes — what breaks (hallucination, refusal, partial answer, wrong format)?
Completion criterion: evaluation report with metrics and failure modes.
4. Iterate
Use failure modes to refine:
- Add constraints where over-generation occurs.
- Add examples where reasoning is shallow.
- Simplify instruction where confusion occurs.
- Add RAG (retrieve relevant docs) when knowledge is missing.
Completion criterion: at least 2 iterations; improvement documented.
5. Recommend
State the best variant with evidence; document when it fails; provide fallback rules.
Completion criterion: recommendation with justification.
Notes
- Pair with
ai-ml-pipeline when the prompt feeds into a model pipeline.
- Use
ai-model-evaluation for deeper evaluation (fairness, robustness, cross-model comparison).
1---2name: ai-prompt-engineering3description: Design, evaluate, and refine prompts for LLMs (GPT-4, Claude, Llama, Mistral) with chain-of-thought, few-shot, RAG, and evaluation metrics.4---56## Contract78- **Input:** task description, target LLM, evaluation criteria.9- **Output:** prompt library + evaluation report + recommendation.10- **Side effects:** may call LLM APIs (cost, data privacy).11- **Dependencies:** LLM API access (OpenAI, Anthropic, local model server).12- **Stop condition:** best variant selected with evaluation evidence.13- **Risk:** medium — LLM outputs can be unreliable; requires validation; data privacy concerns.14- **Boundary:** evaluates and selects prompts; does not deploy to production without additional validation.1516# Prompt Engineering1718Design **LLM prompts** that produce correct, consistent, and useful outputs — with evaluation, iteration, and failure-mode analysis.1920## Process2122### 1. Frame the task23State exactly what the LLM should do:24- Information extraction / summarisation.25- Code generation / explanation.26- Reasoning / proof / analysis.27- Creative generation.28- Classification / labeling.2930**Completion criterion:** task statement precise; success criteria defined.3132### 2. Design the prompt33Structure with clear sections:34- **System message:** role and constraints (e.g. "You are a careful mathematician.").35- **Context:** background, relevant data, rules.36- **Instruction:** what to do; format of output.37- **Examples:** zero-shot, few-shot (2–5 examples with input/output pairs), chain-of-thought (show reasoning steps before answer).38- **Constraints:** length, tone, forbidden content.39- **Output format:** JSON, Markdown, list, single paragraph.4041**Completion criterion:** prompt structure explicit; examples selected.4243### 3. Evaluate variants44Test at least 3 variants (baseline, improved, best guess):45- **Accuracy** — correct vs reference answer.46- **Consistency** — same answer across 3 runs with same prompt (temperature 0 or low).47- **Latency** — time per call.48- **Cost** — tokens used (input + output).49- **Failure modes** — what breaks (hallucination, refusal, partial answer, wrong format)?5051**Completion criterion:** evaluation report with metrics and failure modes.5253### 4. Iterate54Use failure modes to refine:55- Add constraints where over-generation occurs.56- Add examples where reasoning is shallow.57- Simplify instruction where confusion occurs.58- Add RAG (retrieve relevant docs) when knowledge is missing.5960**Completion criterion:** at least 2 iterations; improvement documented.6162### 5. Recommend63State the best variant with evidence; document when it fails; provide fallback rules.6465**Completion criterion:** recommendation with justification.6667## Notes6869- Pair with `ai-ml-pipeline` when the prompt feeds into a model pipeline.70- Use `ai-model-evaluation` for deeper evaluation (fairness, robustness, cross-model comparison).