Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise UserError when tool system_prompt returns a None #1058

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cmungall
Copy link

@cmungall cmungall commented Mar 5, 2025

Previously

@agent.system_prompt
async def func():
    return None

would raise an error at time of model calling

This PR checks defensively checks what is being returned, and will raise a hopefully more informative UserError. Note this all requires a type check override, since returning None is forbidden. However, if we treat user code as input then it's possible to violate at runtime.

Also include a unit test, and for an additional ultra-edgy case of returning a non-string from system_prompt

Fixes #1057

@pytest.mark.parametrize('return_value,valid', [
('', True),
(None, False),
(5, True), ## TODO - decide if this is valid
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either intentionally or accidentally returning a number seems quite unlikely but I decided to cast to str and add a test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide more helpful errors when user accidentally allows None for system_prompt
1 participant