Skip to content

fix(skill_engine): parse LLM JSON despite trailing brace prose#107

Open
santhreal wants to merge 1 commit into
HKUDS:mainfrom
santhreal:fix/extract-json-trailing-prose
Open

fix(skill_engine): parse LLM JSON despite trailing brace prose#107
santhreal wants to merge 1 commit into
HKUDS:mainfrom
santhreal:fix/extract-json-trailing-prose

Conversation

@santhreal

Copy link
Copy Markdown

Problem

_extract_json used a greedy \{.*\} match, so valid JSON followed by prose that contained braces failed to parse and analysis/capture returned None.

Repro

from openspace.skill_engine.analyzer import ExecutionAnalyzer

text = '{"task_completed": true}\n\nReplace {foo} with {bar}.'
assert ExecutionAnalyzer._extract_json(text) == {"task_completed": True}

Fix

Decode from the first { with json.JSONDecoder().raw_decode, matching agents/base.py. Same change in capture_semantic._extract_json.

Greedy \{.*\} matching spanned into later prose braces, so json.loads
failed and analysis/capture dropped valid objects. Use raw_decode from
the first brace, matching agents.base.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant