Skip to content

UserError not raised when invalid tool type is passed to tools parameter #1443

@123Mismail

Description

@123Mismail

Description:
According to the SDK documentation, a UserError should be raised when the user passes an invalid value to the tools parameter (e.g., wrong type).

However, when I pass a string instead of a list of tools, an AttributeError is thrown instead of the documented UserError.

This seems to be due to missing type validation before the SDK iterates over the tools parameter.

Steps to Reproduce:

from openai import OpenAI
from openai.agents import Agent

def predict_weather():
    return "Sunny"

client = OpenAI()

# Passing a string instead of a list of tools
agent = Agent(
    name="TestAgent",
    instructions="Test agent",
    tools="predict_weather"  #  should be a list
)

Expected Behavior:
Raise:

UserError: 'tools' must be a list of Tool objects, not a string.

Actual Behavior:

AttributeError: 'str' object has no attribute 'name'

Possible Fix:
Add an explicit type check in the constructor before iterating over the tools:

if not isinstance(tools, list):
    raise UserError("'tools' must be a list of Tool objects, not a string.")

Note:
The UserError class already exists in the SDK (class UserError(AgentsException)) and is designed to handle such invalid usage scenarios. However, in this case, it’s not triggered because there’s no type check before the code tries to access tool.name.

Environment:

  • SDK version: openai-agents[viz]>=0.2.4
  • Python version: Python 3.13.2
  • OS: Windows-11-10.0.26100-SP0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions