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

  1. Introduction — What a prompt is, why it still matters with agents, course boundaries
  2. Four building blocks — Role, task, constraints, output format
  3. Structure and delimiters — System vs user, XML and Markdown, delimiters

Writing

  1. Few-shot examples — Zero / few-shot, how to pick examples, when not to dump them
  2. Structured output — JSON and schema as a contract; a tiny Pydantic + OpenAI sample
  3. Tools and agents — How prompts change when the model can call tools; MCP / LangChain / Cursor

Engineering

  1. Evaluation — Gold questions, regression, don’t vibe-check only
  2. Pitfalls — Ambiguity, overlong context, leaking secrets, injection awareness
  3. Practical examples — Rewrite a vague prompt three ways, extract JSON, repo agent instructions
  4. Resources — Official docs and follow-on courses on this site

Learning path

StageGoalChapters
1 hourFix one vague instructionIntro → Building blocks → Structure
Half dayWrite reusable, parseable promptsFew-shot → Structured output
1 dayJoin an agent course and self-testTools → Eval → Pitfalls → Examples

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

What you want nextTake from this courseThen read
Edit a repo in an IDE / CLIClear tasks; durable rulesCursor, Claude Code
Build an agent in codesystem_prompt + tool policy + structured finalsLangChain
Visual orchestrationNode prompts still need constraints and formatDify
Plug in external toolsTool schemas are another kind of prompt; say when to use / not use themMCP

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.


Next steps

评论