Skip to content

Commit 8cec33c

Browse files
author
Muhamed Fazal PS
committed
fix: _is_trivial_response no longer skips valid JSON responses (#24)
Removed the naive text.startswith('{') and text.startswith('[') checks in _is_trivial_response that caused all JSON-formatted responses to be classified as trivial. JSON responses like {key: value} are valid structured responses that should be extracted. High symbol-ratio responses (e.g. code snippets) are still correctly caught by the existing code_chars density check (lines 170-174). Updated test assertions to match new behavior. Fixes #24
1 parent 9df3738 commit 8cec33c

2 files changed

Lines changed: 2 additions & 4 deletions

File tree

beliefstate/extractor.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,6 @@ def _is_trivial_response(text: str) -> bool:
172172
code_count = sum(1 for c in text if c in code_chars)
173173
if code_count / len(text) > 0.6:
174174
return True
175-
if text.startswith("{") or text.startswith("["):
176-
return True
177175
return False
178176

179177

tests/test_new_features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ def test_is_trivial_code_block(self):
134134
assert _is_trivial_response("{ } ( ) = ; : # | \\ > <") is True
135135

136136
def test_is_trivial_json_start(self):
137-
assert _is_trivial_response('{"key": "value"}') is True
138-
assert _is_trivial_response('[{"key": "value"}]') is True
137+
assert _is_trivial_response('{"key": "value"}') is False
138+
assert _is_trivial_response('[{"key": "value"}]') is False
139139

140140
def test_not_trivial_substantive(self):
141141
assert _is_trivial_response("I understand your budget constraints.") is False

0 commit comments

Comments
 (0)