ValueError
agentops.exceptions.ToolEventSchemaError
Stack trace
Traceback (most recent call last):
File "main.py", line 42, in <module>
agent.run_tool_event(event_data)
File "/usr/local/lib/python3.10/site-packages/agentops/agent.py", line 128, in run_tool_event
self._validate_event_schema(event_data)
File "/usr/local/lib/python3.10/site-packages/agentops/agent.py", line 98, in _validate_event_schema
raise ToolEventSchemaError(f"Invalid tool event schema: {errors}")
agentops.exceptions.ToolEventSchemaError: Invalid tool event schema: {'missing_field': 'tool_name'} Why it happens
AgentOps expects tool event data to strictly follow a predefined JSON schema. If the event data is missing required fields, has incorrect types, or extra unexpected fields, the schema validation fails and raises this error. This ensures tools receive consistent, validated input.
Detection
Catch ToolEventSchemaError exceptions during tool event processing and log the raw event data and validation errors to identify schema mismatches before they cause downstream failures.
Causes & fixes
Tool event data is missing required fields like 'tool_name' or 'event_type'.
Ensure all required fields defined in the AgentOps tool event schema are present in the event data before sending.
Field types in the event data do not match the schema, e.g., 'timestamp' is a string instead of an integer.
Validate and convert event data fields to the correct types as specified by the schema before passing to AgentOps.
Extra unexpected fields are included in the event data that the schema does not allow.
Remove or whitelist only the allowed fields in the event data to conform exactly to the schema.
Using an outdated or incompatible AgentOps version with a different schema definition.
Upgrade AgentOps to the latest compatible version and update your event data format accordingly.
Code: broken vs fixed
import os
from agentops import Agent
agent = Agent(api_key=os.environ['AGENTOPS_API_KEY'])
event_data = {
# Missing 'tool_name' field
'event_type': 'start',
'timestamp': 1680000000
}
# This line raises ToolEventSchemaError due to schema mismatch
agent.run_tool_event(event_data) import os
from agentops import Agent
agent = Agent(api_key=os.environ['AGENTOPS_API_KEY'])
event_data = {
'tool_name': 'example_tool', # Added required field
'event_type': 'start',
'timestamp': 1680000000
}
# Now runs without schema error
agent.run_tool_event(event_data)
print('Tool event processed successfully') Workaround
Wrap the tool event call in try/except ToolEventSchemaError, then log and manually fix or sanitize the event data before retrying to avoid crashing.
Prevention
Use AgentOps schema validation utilities or JSON schema validators on your event data before sending to AgentOps to guarantee schema compliance and avoid runtime errors.