Skip to content

Empty dynamic system prompt should not add a new message #2519

@Quetute

Description

@Quetute

Initial Checks

Description

Having an empty string as a system_prompt will result in a new message added.
This behavior is not consistent with instruction, for which an empty string do not add a new message (last line in instruction documentation).

Example Code

from pydantic_ai import Agent, RunContext

agent = Agent(
    'openai:gpt-4o', 
    system_prompt="something",  
)


@agent.system_prompt  
def add_nothing() -> str:
    return ""


result = agent.run_sync('foo')
print(result.all_messages())

Python, Pydantic AI & LLM client version

Python 3.13.3
pydantic-ai 0.6.0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions