Skip to content

[Bug] LM Response Returns Nested JSON Object and it breaks the JsonParser #8539

@ali616csayed

Description

@ali616csayed

What happened?

We get the following example outputs from the LM and when it gets to the JSON parser it raises the AdapterParseError in the JSONAdapter class. There is no handling for when nested JSON objects are returned by the LM and it considers these failed outputs. This error is intermittent but hard to handle. Our current fix is just implementing retries when this exception is raised to try for a non nested response/output.

AdapterParseError: Adapter JSONAdapter failed to parse the LM response. LM Response: {"json_input": {"reasoning": "Placeholder reasoning text indicating general analysis.", "actors": ["EntityA"], "details": "Placeholder description about the scenario being analyzed."}}
Expected to find output fields in the LM response: [reasoning, actors, details]
Actual output fields parsed from the LM response: []
AdapterParseError: Adapter JSONAdapter failed to parse the LM response. LM Response: {"json": "{\n "reasoning": "Placeholder reasoning regarding potential interactions.",\n "actors": ["EntityB", "EntityC"],\n "details": "Placeholder explanation of possible behavior or activity."\n}\n</invoke>"}
Expected to find output fields in the LM response: [reasoning, actors, details]
Actual output fields parsed from the LM response: []
AdapterParseError: Adapter JSONAdapter failed to parse the LM response. LM Response: {"json_object": {"reasoning": "Placeholder reasoning referencing an internal process discussion.", "actors": ["EntityD", "EntityE"], "details": "Placeholder information about improving procedural operations."}}
Expected to find output fields in the LM response: [reasoning, actors, details]
Actual output fields parsed from the LM response: []

Steps to reproduce

Use the chainofthought module with output fields defined and keep triggering it until the LM returns a nested json object.

DSPy version

2.6.27

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions