Skip to content

Handle tool errors better in tool registry #2252

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fswair
Copy link
Contributor

@fswair fswair commented Jul 18, 2025

The built-in errors comes from _function_schema origin, related lines, 100, 238, 245.

The issue is basically comes from built-in functions. If we can register a built-in function as a tool, it raise errors.

See main issue for details: #2251

Handle errors better in tool registry
@fswair fswair changed the title Handle tools errors better in tool registry Handle tool errors better in tool registry Jul 18, 2025
@fswair
Copy link
Contributor Author

fswair commented Jul 18, 2025

Tests:

import pytest


def test_builtin_tool_registry():
    """
    Test that built-in functions can be registered as tools.
    """
    from pydantic_ai import Agent, Tool
    from pydantic_ai.exceptions import UserError
    from pydantic_ai.models.test import TestModel
    
    with pytest.raises(UserError):
        Agent(TestModel(), tools=[max])
    
    with pytest.raises(UserError):
        agent = Agent(TestModel())
        agent.tool_plain(min)
    
    agent = Agent(TestModel(), tools=[print])
    assert 'print' in agent._function_toolset.tools
    
    agent._function_toolset.tools.pop('print', None)
    
    agent._function_toolset.add_tool(Tool(print))
    assert 'print' in agent._function_toolset.tools

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.

1 participant