ExamplescriptintermediateRunnableresearch-brief
Text Prompting
Runnable example (intermediate) for script using openai.
Key Facts
- Level
- intermediate
- Runtime
- Python • OpenAI API
- Pattern
- Context-backed research with explicit evidence
- Interaction
- Live sandbox • Script
- Updated
- 14 March 2026
Navigate this example
Library
Browse examplesReopen the wider library to compare adjacent patterns and linked learning paths.Interaction
Run sandbox nowTry the interaction directly in this example’s guided sandbox surface.Source
Open full sourceRead the real implementation, highlighted checkpoints, and runtime requirements.MCP
Call via MCPUse the same resource inside agents, deterministic exports, and MCP setup flows.
Linked principles
02-text-prompting.py
python
from openai import OpenAI
client = OpenAI()
"""
Model spec: https://model-spec.openai.com/2025-02-12.html
Dashboard: https://platform.openai.com/logs?api=responses
"""
# --------------------------------------------------------------
# Introducing instructions
# --------------------------------------------------------------
"""
Inputs can now be a single string or a list of messages.
The list of roles can now be:
- system
- developer
- user
- assistant
"""
response = client.responses.create(
model="gpt-4o",
instructions="Talk like a pirate.",
input="Are semicolons optional in JavaScript?",
)
print(response.output_text)
# --------------------------------------------------------------
# Which would be similar to:
# --------------------------------------------------------------
response = client.responses.create(
model="gpt-4o",
input=[
{"role": "developer", "content": "Talk like a pirate."},
{"role": "user", "content": "Are semicolons optional in JavaScript?"},
],
)
print(response.output_text)
# --------------------------------------------------------------
# The chain of command (hierarchical instructions)
# --------------------------------------------------------------
"""
https://model-spec.openai.com/2025-02-12.html#chain_of_command
"""
response = client.responses.create(
model="gpt-4o",
input=[
{"role": "system", "content": "Talk like a pirate."},
{"role": "developer", "content": "don't talk like a pirate."},
{"role": "user", "content": "Are semicolons optional in JavaScript?"},
],
)
print(response.output_text) # talks like a pirate
response = client.responses.create(
model="gpt-4o",
input=[
{"role": "system", "content": "Don't talk like a pirate."},
{"role": "developer", "content": "Talk like a pirate."},
{"role": "user", "content": "Are semicolons optional in JavaScript?"},
],
)
print(response.output_text) # doesn't talk like a pirate
Related principles
- P4trustApply progressive disclosure to system agencyProvide the minimum information necessary by default, while enabling users to inspect additional detail when confidence, understanding, or intervention is required.Open principle →
- P6visibilityExpose meaningful operational state, not internal complexityPresent the state of the system in language and structures that are relevant to the user, rather than exposing low-level internals that do not support action or understanding.Open principle →
- P7trustEstablish trust through inspectabilityUsers should be able to examine how a result was produced when confidence, accountability, or decision quality is important.Open principle →
- P9orchestrationRepresent delegated work as a system, not merely as a conversationWhere work involves multiple steps, agents, dependencies, or concurrent activities, it should be represented as a structured system rather than solely as a message stream.Open principle →