Prompt Engineering Tutorial
Welcome to the Prompt Engineering primer. This course is based on the OpenAI Prompting guide, OpenAI Prompt engineering, and Anthropic Prompting best practices. It also matches how this site writes agents in Cursor, Claude Code, LangChain, and Dify.
This is a short but complete prerequisite: no product menus. You will learn the contract you send the model every time—role, task, constraints, output format—plus examples, structure, and evaluation. After that, editors, frameworks, and visual builders stop feeling like “prompt magic.”
This course does not teach jailbreaks, prompt-injection exploits, or social engineering. The pitfalls chapter covers defensive awareness only: treat untrusted text as data, not as instructions.
Table of Contents
Basics
- Introduction — What a prompt is, why it still matters with agents, course boundaries
- Four building blocks — Role, task, constraints, output format
- Structure and delimiters — System vs user, XML and Markdown, delimiters
Writing
- Few-shot examples — Zero / few-shot, how to pick examples, when not to dump them
- Structured output — JSON and schema as a contract; a tiny Pydantic + OpenAI sample
- Tools and agents — How prompts change when the model can call tools; MCP / LangChain / Cursor
Engineering
- Evaluation — Gold questions, regression, don’t vibe-check only
- Pitfalls — Ambiguity, overlong context, leaking secrets, injection awareness
- Practical examples — Rewrite a vague prompt three ways, extract JSON, repo agent instructions
- Resources — Official docs and follow-on courses on this site
Learning path
You do not relearn prompting per product. A Cursor chat, a Claude Code CLAUDE.md, a LangChain system_prompt, and a Dify prompt box use the same four blocks.
Prerequisites
- You have used any chat box (ChatGPT, Claude, Cursor Agent, Dify)
- You know a request costs tokens and that context length is finite
- Python is optional. Structured output has ~10 lines of code; skip it and keep the concept
- MCP / LangChain are not required first. Those courses attach this contract to a tool loop
How this course relates to others
How to read: treat the prompt as a contract, rewrite one vague line with the four blocks, then add structure and examples. JSON and tools matter when a program or agent consumes the output. Evaluation is not optional—keep at least ten gold questions before you ship.
When you finish you should be able to:
- Name whether a prompt is missing role, task, constraints, or format
- Separate policy from user paste with tags or fences
- Pin edges with 2–5 examples instead of adjective piles
- Give downstream code a schema, not “JSON-shaped prose”
- Regression-test with gold questions instead of one chat glance
Prefer OpenAI and Anthropic docs as the source of truth. Models change; the contract style stays relatively stable. Keep the Chinese and English trees in sync; a one-locale edit leaves the other readers on a stale contract.