Skip to content

Lesson 11 ยท Prompting Fundamentals

Prompting ChatGPT and GPT Models

Apply OpenAI's official prompting guidance to ChatGPT and the GPT API: message roles, structure with Markdown and XML tags, reasoning models and caching.

The basics from the earlier lessons (clear instructions, context, format and testing) apply to ChatGPT. OpenAI also publishes its own prompting guides for developers. This lesson turns the main ideas into practice, in original words and examples.

The guidance below reflects OpenAI's developer documentation as of December 2026. This tutorial is independent of OpenAI. Newer models get newer advice, so read the guide for the model you use.

Chat and API prompts

In the ChatGPT app you write ordinary messages. Other context, such as your saved settings, can travel with them, so you control only part of what the model receives. In the API you build the request yourself.

For the API, OpenAI separates message roles:

Role or field What goes there
developer message The application's rules; it ranks above user messages
user message The inputs those rules apply to
assistant message Earlier replies from the model
instructions parameter High-level guidance for a response

A helpful comparison from the guide: the developer message is like a function definition, and user messages are like its arguments. Keep stable rules in the developer message and put changing data in user messages.

One detail matters in longer conversations. The instructions parameter applies to the request you send it with. To keep guidance in the conversation across turns, the guide suggests placing it in a first developer message. For the GPT-6.2 models, OpenAI also says that top-level instructions are added after the input, so reusable text belongs in a first developer message to benefit from caching.

Structure the developer message

The guide suggests Markdown headings and lists for sections, and XML tags to mark where reference material starts and ends. A common order is identity, instructions, examples, then context.

TEXT
# Role
You write first drafts of replies for a bicycle repair shop.

# Rules
- Use only facts from the <shop_facts> block.
- If a fact is missing, say that a staff member will confirm it.
- Keep the draft under 120 words.

# Example
<example>
Question: Do you fix electric bikes?
Draft: A staff member will confirm which electric bikes we can service.
</example>

<shop_facts>
Open Tuesday to Saturday. Brake adjustment needs no appointment.
</shop_facts>

The tag names are your own choice. Tags help to separate material from instructions, but they are not a security barrier. Text inside a tag can still try to give orders; see prompt injection.

Build the request in code

This read-only example uses the official openai Python package. DEVELOPER_PROMPT stands for text like the prompt above.

Python
# Read-only: needs an API key
from openai import OpenAI

client = OpenAI()
response = client.responses.create(
    model="gpt-6.2-sol",
    reasoning={"effort": "medium"},
    input=[
        {"role": "developer", "content": DEVELOPER_PROMPT},
        {"role": "user", "content": "Can I bring my bike on Monday?"},
    ],
)
print(response.output_text)

The runnable stand-in below builds only the message list. It calls no model.

Python Stand-in: stable rules first, changing input last

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Putting the unchanging part first matters for prompt caching, which works on a shared beginning of the prompt. A timestamp at the top would break that shared start. Caching also has conditions, such as a minimum length, so this tiny example would not qualify on its own. See cost, latency and caching.

Reasoning models need a different style

OpenAI's guidance says reasoning models handle high-level goals well, while GPT models without reasoning benefit from more explicit direction. Its comparison is a senior colleague who gets a goal, against a junior colleague who gets detailed instructions. Which style fits depends on the model and the effort setting you use.

In practice, for a reasoning model:

  1. State the goal, the constraints and what "done" looks like.
  2. Begin with a short prompt, then add instructions for failures you observe.
  3. Control thinking depth with the reasoning.effort setting, not with repeated requests to think harder. Each model supports its own set of values.
  4. Do not rely on seeing hidden reasoning. Ask for a short explanation or checkable evidence.

OpenAI also publishes advice for specific model generations. For GPT-6.2 Astra, for instance, it notes that the model is already concise, so old "be brief" lines deserve a second look. It also suggests saying when to continue without asking and when to stop for approval. Test such advice on your own cases before you adopt it.

A prompt for the ChatGPT app

You do not need API roles or tags for everyday work. One well-organized message is often enough:

TEXT
Goal: a 2-week revision plan for my driving theory test.
About me: I can study 20 minutes a day. Road signs are my weak area.
Format: a table with day, topic and one quick self-check.
Limits: do not state legal rules from memory; tell me what to look up
in the official handbook.

Common mistakes

  • Copying an old prompt to a new model without testing. Rules written to fix an old weakness can now cause over-careful or badly sized replies.
  • Mixing data into the rules. Keep user-supplied text in user messages or in clearly marked blocks.
  • Settings in prose. Use parameters for effort and output limits, and schemas for structured output.
  • Skipping tests. Official advice is a starting point. Your test set decides.

When you upgrade a model, try removing old instructions one group at a time and rerun your tests. Keep the lines that still make a difference or express a real requirement.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In OpenAI's role scheme, where do your application's lasting rules belong?

    The developer message holds application rules and ranks above user messages.
  2. 2. Why put unchanging text at the start of a prompt?

    Caching relies on a common prefix, so changing content should come later.
  3. 3. What is a sensible first prompt for a reasoning model?

    OpenAI's guidance favors high-level goals for reasoning models; add detail where tests show a need.
  4. 4. What do XML tags around a document guarantee?

    Tags add structure but are not a security control.

Summary

  • In the API, put stable rules in a developer message and changing input in user messages.
  • Use headings and tags for structure; keep stable text first for caching.
  • Give reasoning models goals and constraints, and set effort with the parameter.
  • Read the guide for your model and confirm each change with tests.

Next: Prompting Claude

Your progress is saved in this browser. No account needed.