-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Summary
When streaming tool execution events, QType's chat converter attempts to serialize tool inputs as JSON, but fails when the input contains a datetime object.
Error
TypeError: Object of type datetime is not JSON serializable
Stack Trace
File "qtype/interpreter/stream/chat/converter.py", line 272, in _convert_tool_execution_start
input_json = json.dumps(event.tool_input)
File "json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "json/encoder.py", line 180, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type datetime is not JSON serializableRoot Cause
The flow passes a datetime object as a tool input. When QType tries to stream the tool execution start event, it attempts to serialize the tool inputs to JSON for logging/display purposes. Python's default JSON encoder cannot serialize datetime objects.
Impact
- Prevents streaming of tool execution events
- Breaks conversational interfaces that rely on SSE streaming
- Occurs when datetime variables are passed to tools
Workaround
Instead of passing datetime objects to tools:
- Format datetime to string before passing to tool
- Create wrapper functions that handle date formatting internally
- Use only JSON-serializable types (str, int, float, bool, list, dict) as tool inputs
Resolution Options
- Application Level (Implemented): Create tool wrapper functions that accept only strings
- QType Framework Level: Update the chat converter to use a custom JSON encoder that handles datetime objects
- QType Framework Level: Convert datetime objects to ISO format strings before serialization
Example Fix
# Before (causes error)
def get_data(client: str, timestamp: datetime) -> str:
...
# After (works)
def get_data(client: str, date: str) -> str:
# date should be pre-formatted as "YYYY-MM-DD"
...Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working