Skip to content

json.decoder.JSONDecodeError: Unterminated string starting at #127

Description

@wisteriesDev

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 <cell line: 0>()
     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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions