Skip to content

Tool arguments of type dict are invisible to OpenAI-powered agents #3654

@hinnefe2

Description

@hinnefe2

Initial Checks

Description

Observed behavior

When a pydantic-ai agent powered by an OpenAI model has a tool with an argument of type dict that argument is invisible to the OpenAI model.

Expected behavior

All tool arguments should be visible to the model powering the agent for all model providers.

Example

With a basic agent like

from pydantic_ai import Agent

openai_agent = Agent("openai:gpt-4o")

@openai_agent.tool_plain
def tool_w_dict(name: str, data: dict[str, str]) -> str:
    """A tool with a dict argument.

    Args:
        name: A name string
        data: A dictionary with arbitrary data
    """
    return f"Got {name} with {data}"

@openai_agent.tool_plain
def tool_w_list(name: str, data: list[str]) -> str:
    """A tool with a list argument.

    Args:
        name: A name string
        data: A list with arbitrary data
    """
    return f"Got {name} with {data}"

running a request like

openai_result = openai_agent.run_sync("List all tools you have and their parameters with types")
print(openai_result.output)

produces results like

I have the following tools available:

1. **functions.tool_w_dict**
   - **Parameters**:
     - `name` (string): A name string.

2. **functions.tool_w_list**
   - **Parameters**:
     - `name` (string): A name string.
     - `data` (string[]): A list with arbitrary data.

These tools can handle dictionary-based or list-based inputs, respectively.

Note that the tool_w_dict parameters do not include the dict-typed data argument from the function. This behavior is consistent across many attempts and multiple OpenAI models (I tried gpt-4o, gpt-4o-mini, and gpt-5).

The same agent powered by Anthropic's anthropic:claude-sonnet-4-20250514 model produces output which does include the data argument like

I have access to 2 tools:

## 1. tool_w_dict
**Description:** A tool with a dict argument.
**Parameters:**
- `name` (string, required): A name string
- `data` (object, required): A dictionary with arbitrary data
  - Additional properties: string values only

## 2. tool_w_list
**Description:** A tool with a list argument.
**Parameters:**
- `name` (string, required): A name string
- `data` (array, required): A list with arbitrary data
  - Items: string type only

cc @angsten (who originally discovered this behavior), @physicsrob

Example Code

#!/usr/bin/env python3
# /// script
# requires-python = ">=3.12"
# dependencies = ["pydantic-ai==1.27.0"]
# ///
"""
MRE: Dict-typed arguments are invisible to OpenAI models in pydantic-ai

Run with: uv run mre.py
Requires: OPENAI_API_KEY environment variable
Requires: ANTHROPIC_API_KEY environment variable
"""

import pydantic_ai
import openai
import sys
import anthropic

from pydantic_ai import Agent

openai_agent = Agent("openai:gpt-4o")


@openai_agent.tool_plain
def tool_w_dict(name: str, data: dict[str, str]) -> str:
    """A tool with a dict argument.

    Args:
        name: A name string
        data: A dictionary with arbitrary data
    """
    return f"Got {name} with {data}"


@openai_agent.tool_plain
def tool_w_list(name: str, data: list[str]) -> str:
    """A tool with a list argument.

    Args:
        name: A name string
        data: A list with arbitrary data
    """
    return f"Got {name} with {data}"


anthropic_agent = Agent("anthropic:claude-sonnet-4-20250514")


@anthropic_agent.tool_plain
def tool_w_dict(name: str, data: dict[str, str]) -> str:
    """A tool with a dict argument.

    Args:
        name: A name string
        data: A dictionary with arbitrary data
    """
    return f"Got {name} with {data}"


@anthropic_agent.tool_plain
def tool_w_list(name: str, data: list[str]) -> str:
    """A tool with a list argument.

    Args:
        name: A name string
        data: A list with arbitrary data
    """
    return f"Got {name} with {data}"


openai_result = openai_agent.run_sync(
    "List all tools you have and their parameters with types",
)


anthropic_result = anthropic_agent.run_sync(
    "List all tools you have and their parameters with types"
)

print("Library versions:")
print(f"{sys.version=}")
print(f"{pydantic_ai.__version__=}")
print(f"{openai.__version__=}")
print(f"{anthropic.__version__=}")
print("\n" * 2)

print("OpenAI Agent results:")
print(openai_result.output)
print("\n" * 2)


print("Anthropic Agent results:")
print(anthropic_result.output)

Python, Pydantic AI & LLM client version

sys.version='3.12.12 (main, Oct 31 2025, 23:02:31) [Clang 21.1.4 ]'
pydantic_ai.__version__='1.27.0'
openai.__version__='2.9.0'
anthropic.__version__='0.75.0'

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