Skip to content

[Bug]: parse_partial_json misclassifies incomplete string values and drops existing content #20541

@Shibayan003

Description

@Shibayan003

Bug Description

parse_partial_json contains an internal logic bug when handling incomplete JSON string values.

For inputs where a string value is truncated (e.g. missing the closing quote), the function incorrectly treats the unfinished value as an incomplete key and removes it, even though the key–value structure is already established.

This results in existing value content being dropped and replaced with null, which does not match the intended behavior of completing partial JSON. The issue is caused by incorrect internal logic that determines whether an unfinished string corresponds to an incomplete key or an incomplete value.

I plan to submit a PR to fix this logic.

Version

llama_index_core==0.14.13

Steps to Reproduce

from llama_index.core.llms.utils import parse_partial_json

result = parse_partial_json('{"key": "value') 
print(result) # got {'key': None} expected {'key': 'value'}

Relevant Logs/Tracbacks

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageIssue needs to be triaged/prioritized

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions