Skip to content

[BUG]: LLMObs: AttributeError: type object 'Tool' has no attribute 'run' with pydantic-ai 0.4.4+ #14161

@akotsarelation

Description

@akotsarelation

Tracer Version(s)

3.10.3

Python Version(s)

Python 3.12.7

Pip Version(s)

pip 25.1.1

Bug Report

The application is crashing on LLMObs.enable() if pydantic-ai 0.4.4 or newer is installed.

Reproduction Code

  1. Install ddtrace 3.10.3
  2. Install pydantic-ai-slim 0.4.4 or newer (tested up until 0.4.9)
  3. Execute the following code:
import pydantic_ai
from ddtrace.llmobs import LLMObs
LLMObs.enable()

Observe the following error:

  File "/some/path/lib/python3.12/site-packages/ddtrace/llmobs/_llmobs.py", line 518, in enable
    cls._patch_integrations()
  File "/some/path/lib/python3.12/site-packages/ddtrace/llmobs/_llmobs.py", line 732, in _patch_integrations
    patch(raise_errors=True, **integrations_to_patch)
  File "/some/path/lib/python3.12/site-packages/ddtrace/_monkey.py", line 387, in patch
    when_imported(module)(
  File "/some/path/lib/python3.12/site-packages/wrapt/importer.py", line 293, in register
    register_post_import_hook(hook, name)
  File "/some/path/lib/python3.12/site-packages/wrapt/importer.py", line 79, in register_post_import_hook
    hook(module)
  File "/some/path/lib/python3.12/site-packages/ddtrace/_monkey.py", line 275, in on_import
    imported_module.patch()
  File "/some/path/lib/python3.12/site-packages/ddtrace/contrib/internal/pydantic_ai/patch.py", line 55, in patch
    wrap(pydantic_ai, "tools.Tool.run", traced_tool_run(pydantic_ai))
  File "/some/path/lib/python3.12/site-packages/wrapt/patches.py", line 114, in wrap_function_wrapper
    return wrap_object(module, name, FunctionWrapper, (wrapper,))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/some/path/lib/python3.12/site-packages/wrapt/patches.py", line 60, in wrap_object
    (parent, attribute, original) = resolve_path(module, name)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/some/path/lib/python3.12/site-packages/wrapt/patches.py", line 52, in resolve_path
    original = lookup_attribute(parent, attribute)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/some/path/lib/python3.12/site-packages/wrapt/patches.py", line 44, in lookup_attribute
    return getattr(parent, attribute)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'Tool' has no attribute 'run'

Error Logs

No response

Libraries in Use

aiohappyeyeballs==2.6.1
aiohttp==3.12.14
aiosignal==1.4.0
aiosqlite==0.20.0
alembic==1.13.3
annotated-types==0.7.0
anyio==4.9.0
asyncmy==0.2.10
attrs==25.3.0
black==25.1.0
boto3==1.39.15
botocore==1.39.15
bytecode==0.16.2
certifi==2025.7.14
cffi==1.17.1
charset-normalizer==3.4.2
click==8.2.1
colorama==0.4.6
coverage==7.10.1
cryptography==44.0.3
dapr==1.15.0
ddtrace==3.10.3
envier==0.6.1
eval_type_backport==0.2.2
fastapi==0.116.1
flake8==7.0.0
flake8-black==0.3.6
frozenlist==1.7.0
googleapis-common-protos==1.70.0
greenlet==3.2.3
griffe==1.9.0
grpcio==1.74.0
grpcio-status==1.74.0
h11==0.16.0
httpcore==1.0.9
httpx==0.28.1
idna==3.10
importlib_metadata==8.7.0
iniconfig==2.1.0
isort==6.0.1
jmespath==1.0.1
jsonschema==4.25.0
jsonschema-path==0.3.4
jsonschema-specifications==2025.4.1
lazy-object-proxy==1.11.0
logfire-api==4.0.0
Mako==1.3.10
MarkupSafe==3.0.2
mccabe==0.7.0
multidict==6.6.3
mypy==1.17.0
mypy_extensions==1.1.0
openapi-schema-validator==0.6.3
openapi-spec-validator==0.7.2
opentelemetry-api==1.35.0
packaging==25.0
pastel==0.2.1
pathable==0.4.4
pathspec==0.12.1
platformdirs==4.3.8
pluggy==1.6.0
poethepoet==0.36.0
propcache==0.3.2
protobuf==6.31.1
pycodestyle==2.11.1
pycparser==2.22
pydantic==2.11.7
pydantic-ai-slim==0.4.5
pydantic-graph==0.4.5
pydantic-settings==2.10.1
pydantic_core==2.33.2
pyflakes==3.2.0
Pygments==2.19.2
PyJWT==2.10.1
pytest==8.4.1
pytest-asyncio==0.26.0
pytest-cov==6.0.0
python-dateutil==2.9.0.post0
python-dotenv==1.1.1
PyYAML==6.0.2
referencing==0.36.2
requests==2.32.4
rfc3339-validator==0.1.4
rpds-py==0.26.0
s3transfer==0.13.1
six==1.17.0
sniffio==1.3.1
SQLAlchemy==2.0.41
starlette==0.47.2
structlog==24.4.0
types-protobuf==6.30.2.20250703
types-PyMySQL==1.1.0.20250711
types-python-dateutil==2.9.0.20250708
types-PyYAML==6.0.12.20250516
types-requests==2.32.4.20250611
types-setuptools==80.9.0.20250529
types-six==1.17.0.20250515
types-ujson==5.10.0.20250326
typing-inspection==0.4.1
typing_extensions==4.14.1
urllib3==2.5.0
uvicorn==0.35.0
wrapt==1.17.2
xmltodict==0.14.2
yarl==1.20.1
zipp==3.23.0

Operating System

Darwin Kernel Version 24.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions