Instructions and message roles

OpenAI API · Essentials · 8 min

Separating your rules from the user's text is the basis of predictable behaviour.

Most apps have two kinds of text: your fixed rules ("You are a support assistant for Acme; answer briefly") and the user's changing question. The Responses API gives each its own place.

instructions holds the rules. It works like a system prompt: the model treats it as guidance from you, the developer, and gives it priority over user text.

input can be a list of messages, each a dict with a role and content. Roles you will use:

  • user: what the person typed.
  • assistant: an earlier reply from the model.
  • system: developer guidance placed inside the input list, an alternative to instructions.

A list lets you include earlier turns, or a worked example of the answer style you want.

A gotcha: instructions apply only to the request they are sent with. When you chain requests with previous_response_id (a later lesson), earlier instructions do not carry over, so send them every time.

Write instructions like a brief to a new colleague: who the model is, what the task is, what format to use, and what to avoid. Explain why a rule exists; models follow reasons better than bare commands.

Example

from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-6-astra",
    instructions=("You are a friendly cooking assistant. Answer in at most "
                  "three sentences, because users read on a phone."),
    input=[
        {"role": "user", "content": "How do I keep rice from sticking?"},
    ],
)
print(response.output_text)

Remember

  • instructions = your rules; input = the conversation
  • Input messages use roles: user, assistant, system
  • Resend instructions on every request; they don't carry over

Watch out for

  • Assuming instructions from the first request still apply when chaining with previous_response_id.

Check yourself

  1. You chain a follow-up with previous_response_id. What happens to the first call's instructions?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: developers.openai.com/api/docs/guides/prompt-engineering