1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
29 small wins to finish your pathNext lesson →
Instructions: what the model is told
Instructions are the text that tells the model its job; they can be a fixed string, a function that runs at the start of every run, or extra text for one run.
Last updated: 28 Sep, 2026 · Pydantic AI 2.51
The model function in FunctionModel: write a stand-in model read the ticket. Here it reads info.instructions instead and answers with them, so you see the exact text a real model would be sent.
Answering with the instructions received
from pydantic_ai import Agent, ModelResponse, TextPart
from pydantic_ai.models.function import FunctionModel
def show_instructions(messages, info):
return ModelResponse(parts=[TextPart(info.instructions or "(no instructions)")])
spy = FunctionModel(show_instructions)Setting a fixed instruction string
agent = Agent(spy, instructions="You answer support tickets for an online shop.")
print(agent.run_sync("hi").output)Output
You answer support tickets for an online shop.
Adding instructions that change each run
shop_status stands for something your app knows, such as a delivery problem. A function registered with @agent.instructions runs at the start of every run:
@agent.instructions
def deliveries() -> str:
if shop_status["delayed"]:
return "Deliveries are running two days late. Say so when asked about a parcel."
return ""
print(agent.run_sync("hi").output)
print("---")
shop_status["delayed"] = True
print(agent.run_sync("hi").output)Output
You answer support tickets for an online shop. --- You answer support tickets for an online shop. Deliveries are running two days late. Say so when asked about a parcel.
Why the second run differs
- The function runs per run, so the second run sees the shop as it is at that moment.
- Returning an empty string adds nothing, which is why the first run shows only the fixed text.
- All the pieces are joined into one string, separated by blank lines, and sent to the model.
Adding instructions for one run
agent = Agent(spy, instructions="You answer support tickets for an online shop.")
print(agent.run_sync("hi", instructions="Reply in Hindi.").output)Output
You answer support tickets for an online shop. Reply in Hindi.
Text passed to run_sync is added for that run only, after the agent's own instructions.
instructions vs system_prompt
| instructions | system_prompt | |
|---|---|---|
| Stored in the messages | No | Yes |
| Sent when a chat continues | The current agent's, freshly | The stored one, again |
| Docs recommend | Yes, by default | Only to keep the old prompt |
When to use each kind
- A fixed string for the agent's standing job.
- An
@agent.instructionsfunction for anything that changes between runs, such as live shop status. - Per-run text for a one-off tweak, such as a language for this reply.
Watch out. Instructions are not stored in the message list, so a continued conversation always sends the current agent's instructions, not the ones from the first run. Use
system_prompt when you need the original text kept.Related
- Previous: FunctionModel: write a stand-in model
- Next: Real models: providers, keys and model names
- Reference: Instructions
Try it yourself
- Register a second
@agent.instructionsfunction and see where its text appears. - Return
Nonefromdeliveriesinstead of an empty string. - Pass
instructions=["Be short.", "Be kind."]toAgent.
Every expert started right here.