Prompt Engineering
Source-check date
This material was checked on 2026-07-21. Prompting strategies evolve with models, APIs, and safety mechanisms. This knowledge base separates transferable engineering methods from provider-specific behavior. Before using an online model, recheck the current documentation for the selected provider and validate it against your own evaluation set.
Course overview
Prompt engineering is not a search for a magic phrase. It is the work of expressing a business goal as a testable input contract: define the task, input boundary, constraints, output format, and success criteria, then validate them with representative examples. Transferable methods include task definition, separating data from instructions, contract validation, version management, and evaluation. Role names, supported schema features, prompt caching, and hosting mechanisms can vary by provider and model. A prompt cannot replace correct data, model selection, retrieval, access control, or programmatic validation.
Where this fits in the overall path
This course belongs to the LLM Application Foundations stage. After learning the basics of APIs, JSON, and Markdown, use Modern LLM Capabilities and Model Selection to define the required capabilities and hard gates, then learn here how to communicate an intent precisely. Continue with Context Engineering to organize evidence and state, and LLM API Integration to connect prompts to reliable software.
Learning objectives
- Turn an ambiguous request into a task statement with success criteria.
- Use roles, delimiters, examples, and counterexamples correctly, and identify which practices are provider-specific.
- Constrain machine-readable output with JSON Schema or an equivalent contract, then continue validating semantics in application code.
- Version prompt templates and drive iterations with fixed cases and metrics.
- Recognize prompt injection and establish a trust boundary between instructions and untrusted data.
Prerequisites
- Read basic Markdown, JSON, and Python.
- Understand the basic idea of HTTP requests and responses.
- No machine-learning mathematics background or model API key is required.
Recommended order
- Task definition, instruction hierarchy, and boundaries: define success before writing instructions.
- Zero-shot prompting, examples, and counterexamples: learn when examples help and how to avoid example bias.
- Structured output and contracts: make output safe for programs to consume.
- Templates, variables, and version management: turn a one-off prompt into a maintainable asset.
- Evaluation-driven iteration: use evidence, not impressions, to decide whether a change improves the task.
- Prompt injection and trust boundaries: treat external text as data and minimize possible impact.
- Prompt experiment project and self-check: complete an offline classification-contract experiment.
Hands-on entry point
Start with the prompt experiment project. It includes an offline experiment script, 12 versioned cases, a response schema, and unit tests. It requires neither network access nor credentials. It verifies role separation, strict JSON, version bindings between prompt code and schema, case annotation evidence, fail-closed contract drift, grounded evidence, asset hashes, exit codes, and slice statistics. It does not validate the real quality of any online model.
Mastery criteria
- Write the input, output, constraints, and refusal conditions for a real task.
- Explain the difference between valid JSON and an output that both matches a schema and is semantically correct.
- Compare two prompt versions with at least ten representative cases; record failures by slice and risk rather than relying only on a global average.
- Explain why a single defensive sentence cannot solve prompt injection, and propose permission, validation, and human-confirmation controls.
- Make template changes, model configuration, and evaluation results traceable to one another.
- Run the course’s 19 offline tests and ensure bad responses, malformed cases, or contract drift fail with the specified nonzero status.
Connections to other knowledge bases
- Modern LLM Capabilities and Model Selection determines whether a candidate has the reasoning, structured-output, tool, and modality capabilities that the task requires. Prompting cannot compensate for a missed capability or privacy hard gate.
- Context Engineering decides which material enters a prompt, in what order, and within what budget.
- LLM API Integration handles role mapping, timeouts, retries, streaming events, usage, and logs.
- RAG supplies traceable evidence; Evaluation Framework determines whether a prompt change actually improves task performance.
- AI Safety and the authorization system limit impact after failure. Tool Calling connects validated model suggestions to real actions.
Primary references
- OpenAI: Prompt engineering (accessed 2026-07-21)
- OpenAI: Structured Outputs (accessed 2026-07-21)
- OpenAI: Deprecations (accessed 2026-07-21)
- OpenAI: Safety best practices (accessed 2026-07-21)
- Anthropic: Prompt engineering overview (accessed 2026-07-21)
- Anthropic: Mitigate jailbreaks and prompt injections (accessed 2026-07-21)
- Google AI for Developers: Prompt design strategies (accessed 2026-07-21)
- JSON Schema: Getting started (accessed 2026-07-21)
- Perez and Ribeiro, Ignore Previous Prompt: Attack Techniques For Language Models (original paper)