Skip to content

Advanced

Prompt Engineering Basics: Write Instructions That Work

A practical five-part prompt framework—role, task, context, format, constraints—with templates, failure patterns, and reusable scenarios.

·14 min read·Last updated: 1/10/2026

Prompt 工程入门:把指令写清楚的系统方法

What “prompt engineering” actually means

A prompt is the instruction and context you send to ChatGPT. Engineering it means making the request executable: clear goal, explicit constraints, and a checkable output. On ChatGPT or via the OpenAI API, better prompts often beat blindly switching models.

The five-part framework

  1. Role — who should the model act as?
  2. Task — what verb: summarize, rewrite, compare, generate?
  3. Context — audience, background, source material, business rules
  4. Format — Markdown, table, JSON, numbered steps
  5. Constraints — length, tone, bans, required coverage

Template

You are a science writer for non-technical readers.
Task: Explain what a vector database is and how it differs from a regular database.
Audience: junior product managers.
Format: 80-word summary, then three short sections, then one everyday analogy.
Constraints: Avoid jargon piles; when a term is required, define it in parentheses; do not invent market-share numbers.

Advanced techniques

Few-shot examples

Show 1–3 input/output pairs before the real task—great for titles, support macros, or extraction.

Stepwise reasoning for hard problems

Ask for steps before the final answer to reduce skipped logic. Still verify; steps are not a correctness guarantee.

Structured outputs

Return JSON only with fields title, summary, tags (array), risk_level (low|mid|high). No extra prose.

Iterate on purpose

Skeleton → details → tone pass. Treat the model as a co-editor, not a one-click oracle.

Weak vs strong prompts

Weak promptProblemFix
“Write something”No goalSpecify genre, length, use
“Make it more professional”Vague barDefine reader and jargon level
“Use the latest online news”Hallucination riskPaste verified sources; mark uncertainty
“Think with the strongest model”Empty instructionProvide scoring criteria and must-cover points

Reusable scenarios

  • Meeting notes → table of decisions / owners / due dates
  • Code review → correctness, readability, performance, security
  • Learning plan → level, weekly hours, 4-week milestones and acceptance checks

API connection

The web UI is for exploration; production pipelines belong on platform.openai.com with Docs. Freeze winning prompts as system + user templates with version control.

Practice

Upgrade “Please improve this product blurb” into a five-part prompt that returns: diagnosis, three rewrites (formal / friendly / concise), and a recommendation with reasons.

Takeaway

A good prompt is a mini specification. Write the five parts, iterate on evidence, and verify facts yourself. Continue with Effective Asking and the Latest Model Guide.

Related

← All tutorials