fix: Use proper JSON serialization for tool responses#2
Merged
dankelleher merged 2 commits intomainfrom Feb 9, 2026
Merged
Conversation
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
Add isinstance checks before accessing .text on ResponseType union members to satisfy pyright's reportAttributeAccessIssue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
str()withorjson-based JSON serialization informat_text_responseandtop_queries_calcso that structured data (lists/dicts) produces valid JSON instead of Python repr output (single quotes,None,datetime.datetime(...)etc.)orjsondependency with a custom default handler for PostgreSQL-specific types (Decimal,timedelta,bytes,memoryview,set/frozenset)format_text_responseunchanged; only structured data gets JSON serialization