fix(extractor): don't skip JSON responses carrying natural language (#24)#31
Open
santosh2345 wants to merge 1 commit into
Open
fix(extractor): don't skip JSON responses carrying natural language (#24)#31santosh2345 wants to merge 1 commit into
santosh2345 wants to merge 1 commit into
Conversation
_is_trivial_response() blanket-skipped any response starting with '{' or
'[', so an LLM answer wrapped in JSON like
{"answer": "the user's budget is $20k, they prefer Python"} was
classified as trivial and never extracted. Closes AltioraLabs#24.
- Replace the naive startswith('{'/'[') check with classify_response_type:
skip pure "sql"/"code" payloads, but for "json" only skip when the
payload's string values contain no meaningful prose (< 5 word-like
tokens). Pure data payloads such as {"key": "value"} stay trivial.
- Make the code-character density heuristic whitespace-insensitive so
symbol soup like "{ } ( ) = ;" is still caught now that the startswith
guard is gone.
- Tests: JSON-with-prose is non-trivial (regression), pure-data JSON stays
trivial, SQL and code fences stay trivial.
abhay-2108
requested changes
Jul 16, 2026
abhay-2108
left a comment
Collaborator
There was a problem hiding this comment.
Excellent work resolving #24. The recursive JSON walk is clean, and the whitespace-insensitive updates to the density check are a great touch.
One small suggestion to make this future-proof:
Internationalization (i18n) Support: The _json_prose_word_count function uses re.findall(r"[A-Za-z]{2,}", obj) to count words. If a developer uses a non-English language (like Spanish, French, Chinese, or Japanese), this regex will under-count or miss the prose, causing those valid JSON responses to be incorrectly flagged as trivial.
Suggested Fix: Using a unicode-aware regex pattern like \w{2,} (or a basic character length count on string values) will make this language-agnostic.
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.
Closes #24.
_is_trivial_response()blanket-skipped any response starting with{or[. So an LLM answer wrapped in JSON — e.g.{"answer": "The user's budget is $20k, they prefer Python"}— was treated as trivial and produced zero extracted beliefs.Note on the proposed fix
The issue suggested
if classify_response_type(text) in ("json", "sql", "code"): return True. That alone doesn't fix the issue's own example: the example is valid JSON, soclassify_response_typereturns"json"and it would still be skipped. This PR skipsjsononly when it's a pure data payload.Changes
startswith('{' / '[')check withclassify_response_type:"sql"/"code"→ trivial (skip)."json"→ trivial only when the payload's string values contain no meaningful prose (< 5word-like tokens).{"key": "value"}stays trivial; JSON wrapping a real sentence does not."{ } ( ) = ;"is still caught now that thestartswithguard is gone.Tests
{"key": "value"},[{"key": "value"}]) → still trivial._is_trivial_responsetests kept.Verification
pytest tests/test_new_features.py tests/test_extractor.py tests/test_extractor_helpers.py→ 95 passed. Full suite: 389 passed (2 pre-existing failures are unrelated missing optional deps —flask,litellm).