Skip to content

fix: Use proper JSON serialization for tool responses#2

Merged
dankelleher merged 2 commits intomainfrom
fix/json-serialization-tool-responses
Feb 9, 2026
Merged

fix: Use proper JSON serialization for tool responses#2
dankelleher merged 2 commits intomainfrom
fix/json-serialization-tool-responses

Conversation

@dankelleher
Copy link
Member

@dankelleher dankelleher commented Feb 9, 2026

Summary

  • Replace str() with orjson-based JSON serialization in format_text_response and top_queries_calc so that structured data (lists/dicts) produces valid JSON instead of Python repr output (single quotes, None, datetime.datetime(...) etc.)
  • Add orjson dependency with a custom default handler for PostgreSQL-specific types (Decimal, timedelta, bytes, memoryview, set/frozenset)
  • Strings pass through format_text_response unchanged; only structured data gets JSON serialization

Replace str() with orjson-based JSON serialization in format_text_response
and top_queries_calc so that structured data (lists/dicts) produces valid
JSON instead of Python repr output. This fixes programmatic consumption
of tool results where JSON.parse() would fail on single quotes, None, etc.

- Add orjson dependency with custom handler for PostgreSQL types (Decimal,
  timedelta, bytes, memoryview, set/frozenset)
- Strings pass through format_text_response unchanged; structured data
  gets JSON serialization
- Add unit tests for all PostgreSQL type serialization paths
- Add integration test verifying valid JSON from real PostgreSQL queries
@dankelleher dankelleher closed this Feb 9, 2026
@dankelleher dankelleher reopened this Feb 9, 2026
Add isinstance checks before accessing .text on ResponseType union
members to satisfy pyright's reportAttributeAccessIssue.
@dankelleher dankelleher merged commit 1824750 into main Feb 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant