json.decoder.JSONDecodeError: Unterminated string starting at
- Dominant language
- Python
- Stars
- 38.6k
- Forks
- 2.7k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 3
Description
Hello.
I get json parse errors from resolver.py due to propably wrong structured output from llm
### code:
```
try:
result_generator = lx.extract(
text_or_documents=comment_texts,
prompt_description=topic_prompt,
examples=topic_examples,
model_id="gemini-2.5-flash",
debug=True,
}
except Exception as e:
print(f"Caught a parsing error: {e}")
print(f"Extracted {len(result_generator.str)} entities from {len(result_generator.text):,} characters")
#trying to save output for debug
with open("jsondebugtest.jsonl", "w") as f:
for result in result_generator:
f.write(result.text)
f.write("\n")
```
### error trace:
```
`LangExtract: model=gemini-2.5-flash, current=322 chars, processed=322 chars: [00:00]ERROR:absl:Failed to parse content.
Traceback (most recent call last):
File "/usr/local/lib/python3.11/dist-packages/langextract/resolver.py", line 349, in _extract_and_parse_content
parsed_data = json.loads(content)
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Unterminated string starting at: line 4 column 16 (char 42)
LangExtract: model=gemini-2.5-flash, current=322 chars, processed=322 chars: [04:42]Caught a parsing error: Failed to parse content.
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
[/tmp/ipython-input-1112811029.py](https://localhost:8080/#) in ()
19 print(f"Caught a parsing error: {e}")
20
---> 21 print(f"Extracted {len(result_generator.str)} entities from {len(result_generator.text):,} characters")
22 with open("jsondebugtest.jsonl", "w") as f:
23 for result in result_generator:
NameError: name 'result_generator' is not defined`
```
**Is there any way to output raw LLM output /inference api response before its go to resolver.py ?**
its hard to get proper prompt and proper structured output without easy way to debugging llm output
Contributor guide
Research direction
Reproduce the Gemini extraction example, then inspect resolver.py around _extract_and_parse_content, where the trace shows json.loads(content) failing. Trace how the model response reaches the parser and define the debugging output needed before parsing; done means the raw response can be inspected when parsing fails.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai, developer-experience
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100