{"record":{"id":"309a7dab505869a0","repo":"unicity-aos/aos-ce","slug":"failed-to-parse-label-from-prompt-builder-e","errorCode":null,"errorMessage":"Failed to parse {label} from prompt builder: {e}","messagePattern":"Failed to parse (.+?) from prompt builder: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"capsules/capsule-react/src/lib.rs","lineNumber":2113,"sourceCode":"\n/// Parse a JSON array field from a payload, deserializing each element.\n///\n/// Logs a warning for each element that fails to deserialize and skips it.\n/// Returns an empty vec if the field is missing or not an array.\nfn parse_json_array_field<T: serde::de::DeserializeOwned>(\n    payload: &serde_json::Value,\n    key: &str,\n    label: &str,\n) -> Vec<T> {\n    payload\n        .get(key)\n        .and_then(|v| v.as_array())\n        .map(|arr| {\n            arr.iter()\n                .filter_map(|v| {\n                    serde_json::from_value::<T>(v.clone())\n                        .map_err(|e| {\n                            log::warn(format!(\"Failed to parse {label} from prompt builder: {e}\"));\n                            e\n                        })\n                        .ok()\n                })\n                .collect()\n        })\n        .unwrap_or_default()\n}\n\n#[cfg(test)]\nmod tests {\n    use super::*;\n\n    /// Build an `ActiveLlm` for tests without going through the registry.\n    fn active(topic: &str, model: Option<&str>) -> ActiveLlm {\n        ActiveLlm {\n            topic: topic.to_string(),\n            model: model.map(str::to_owned),","sourceCodeStart":2095,"sourceCodeEnd":2131,"githubUrl":"https://github.com/unicity-aos/aos-ce/blob/f6f22024fb1e8d122f28a1b4a9f75aee448ae839/capsules/capsule-react/src/lib.rs#L2095-L2131","documentation":"capsule-react parses items returned by the prompt builder into typed values T. When an individual array element fails serde_json::from_value, this warning is logged with the label (e.g., the item kind) and the element is skipped via filter_map — parsing continues for remaining items rather than failing the whole collection.","triggerScenarios":"An element of the prompt-builder's JSON array does not deserialize into T — wrong field names/types for the expected struct, missing required fields, or an unexpected shape for that label.","commonSituations":"Prompt builder emitting a slightly different schema for one item kind; LLM-generated JSON with malformed entries mixed with valid ones; version drift between capsule-react and the prompt builder's output format.","solutions":["Inspect the {e} message and the offending array element's fields; fix the prompt builder output or the T struct to match.","Add serde defaults/Option fields to tolerate optional data in T.","Ensure capsule-react and the prompt builder agree on the item schema version.","Check whether items come from LLM output and tighten the prompt/schema enforcement for that field."],"exampleFix":"// before\nserde_json::from_value::<T>(v.clone()) // element missing required field\n// after\n#[derive(Deserialize)]\nstruct Item { required: String, #[serde(default)] optional: Option<String> }\nserde_json::from_value::<T>(v.clone())","handlingStrategy":"validation","validationCode":"function isParseable(v) {\n  try { JSON.parse(JSON.stringify(v)); return typeof v === 'object' && v !== null; }\n  catch { return false; }\n}","typeGuard":"fn parse_item<T: DeserializeOwned>(v: &serde_json::Value) -> Option<T> {\n    serde_json::from_value::<T>(v.clone()).ok()\n}","tryCatchPattern":"match serde_json::from_value::<T>(v.clone()) {\n    Ok(item) => Some(item),\n    Err(e) => { log::warn(\"Failed to parse {label} from prompt builder: {e}\"); None }\n}","preventionTips":["Keep prompt-builder output schema and T struct in sync","Use serde defaults for optional fields","Consume items tolerantly (skip-and-log) as the library does"],"tags":["json","deserialization","prompt-builder","schema"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"f6f22024fb1e8d122f28a1b4a9f75aee448ae839","analyzedAt":"2026-09-13T03:04:44.565Z","contentChangedAt":"2026-09-13T03:04:44.565Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}