Skip to content

Mandatory input parameter after switching to the OpenAI Responses API #3369

@pietz

Description

@pietz

Initial Checks

Description

When switching from OpenAIChatModel to OpenAIResponseModel, I noticed that the input parameter is now mandatory when providing input dependencies to the run() function.

from pydantic import BaseModel
from pydantic_ai import Agent, RunContext
from pydantic_ai.models.openai import OpenAIChatModel, OpenAIResponsesModel

class Payload(BaseModel):
    topic: str
    sentences: int


payload = Payload(topic="artificial intelligence", sentences=3)

chat_model = OpenAIChatModel("gpt-5-mini")
chat_agent = Agent(chat_model, instructions="Generate an article.", deps_type=Payload)

@chat_agent.instructions
def chat_context(ctx: RunContext[Payload]) -> str:
    return f"Topic: {ctx.deps.topic}\nSentences: {ctx.deps.sentences}"


resp_model = OpenAIResponsesModel("gpt-5-mini")
resp_agent = Agent(resp_model, instructions="Generate an article.", deps_type=Payload)

@resp_agent.instructions
def responses_context(ctx: RunContext[Payload]) -> str:
    return f"Topic: {ctx.deps.topic}\nSentences: {ctx.deps.sentences}"


res1 = chat_agent.run_sync(deps=payload)
res2 = resp_agent.run_sync(deps=payload)

In this case, the first example will run, while the second will throw an error indicating that I need to add the input to the run function.

Is this a limitation from the OpenaiAI Responses API or did the Pydantic team to change this behavior?

For many AI workflows that I build I provide the context of what needs to be done in the instructions, so that at runtime I only need to feed in the structured data. I don't need or want to add another prompt. Sure, I could do agent.run("", deps=payload), but I hope you can see that this feels a bit weird.

Example Code

Python, Pydantic AI & LLM client version

Python 3.12
PAI: 1.11.1
See example

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersquestionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions