Skip to content

Raise UserError when tool system_prompt returns a None #1058

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

Closed
wants to merge 3 commits into 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.

@DouweM
Copy link
Contributor

DouweM commented Apr 30, 2025

@cmungall Thanks for working on this and our apologies for the late response... There's another PR that adds explicitly support for None system prompts: #864. That one's been stalled for a bit as well, but I think we'll get it merged soon. So I'll close this for the moment, due to be reopened if we decide not to go the other route.

@DouweM DouweM closed this Apr 30, 2025
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
2 participants