fix(cpp): add null-safety checks for JSON string fields in LLM response parsing#780
Conversation
…se parsing Some smaller LLM models (e.g. qwen3.5:9b) return null for JSON fields like "tool" or "content" instead of omitting them. json.contains() returns true for null values, but .get<std::string>() throws type_error.302. Add .is_string() / .is_null() guards before all .get<std::string>() calls on LLM response fields across agent.cpp, json_utils.cpp, and clean_console.cpp.
|
@claude please review this PR. |
|
Claude finished @kovtcharov's task —— View job Review Complete
Summary🟢 LGTM - This PR correctly addresses the crash caused by Code ReviewChanges look good. The fix properly guards all
Minor Observations
VerificationThe fix correctly identifies that |
|
@claude can you explain why the following tests are failing? https://github.com/amd/gaia/actions/runs/24406513448/job/71422231020?pr=780 |
|
Claude finished @kovtcharov's task —— View job Unable to fetch CI logs
I'm not able to retrieve the logs for run 24406513448 / job 71422231020 from this environment — the required commands ( A few options to move forward:
What I can say about this PR's likely impactLooking at the changes in this PR (null-safety guards only, no signature changes, no control-flow changes beyond "skip extraction when field is null"), the risk of it breaking tests is low and narrow:
If the failures are in any of those three test files, that's almost certainly where to look first. If the failures are in Python tests ( Happy to do a targeted analysis as soon as you can share the failing test names or the relevant log snippet. |
|
@claude is the failing c++ test a result of this PR? |
Summary
.is_string()/.is_null()guards before all.get<std::string>()calls on LLM response JSON fieldsjson.exception.type_error.302: type must be string, but is null) when smaller LLM models (e.g.qwen3.5:9b) returnnullfor fields like"tool"or"content"instead of omitting themjson.contains()returnstruefor null values, so the existing checks were insufficientFiles changed
cpp/src/json_utils.cpp—parseLlmResponse(): guardtoolandanswerfieldscpp/src/agent.cpp—callLlm(): guardcontentfield in both streaming fallback and non-streaming pathscpp/src/clean_console.cpp— display methods: guardtool,command,error,output,statusfieldsTest plan
qwen3.5:9b(previously crashing) now completes successfullyqwen3:8bandqwen3.5:cloudstill work./tests_mock)