{"record":{"id":"3b7cc2a935ac1861","repo":"BoundaryML/baml","slug":"could-not-infer-child-type","errorCode":null,"errorMessage":"Could not infer child type","messagePattern":"Could not infer child type","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs","lineNumber":317,"sourceCode":"                let mapped_fields: BamlMap<String, BamlValueWithMeta<(T, TypeIR)>> = pairs\n                    .into_iter()\n                    .map(|(key, val)| {\n                        let sub_value =\n                            self.distribute_type_with_meta(val, annotation_value_type.clone())?;\n\n                        Ok((key, sub_value))\n                    })\n                    .collect::<anyhow::Result<BamlMap<String, BamlValueWithMeta<(T, TypeIR)>>>>()?;\n\n                Ok(BamlValueWithMeta::Map(mapped_fields, (meta, field_type)))\n            }\n\n            BamlValueWithMeta::List(items, meta) => {\n                let new_items = items\n                    .into_iter()\n                    .map(|i| {\n                        item_type(self, &field_type)\n                            .ok_or(anyhow::anyhow!(\"Could not infer child type\"))\n                            .and_then(|item_type| self.distribute_type_with_meta(i, item_type))\n                    })\n                    .collect::<Result<Vec<_>>>()?;\n                Ok(BamlValueWithMeta::List(new_items, (meta, field_type)))\n            }\n\n            BamlValueWithMeta::Media(m, meta)\n                if self.is_subtype(\n                    &TypeIR::Primitive(TypeValue::Media(m.media_type), Default::default()),\n                    &field_type,\n                ) =>\n            {\n                Ok(BamlValueWithMeta::Media(m, (meta, field_type)))\n            }\n            BamlValueWithMeta::Media(_, _) => {\n                anyhow::bail!(\"Could not unify Media with {:?}\", field_type)\n            }\n","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs#L299-L335","documentation":"When distributing types over a List value, BAML needs the element type of the expected TypeIR via `item_type`. If the expected type has no list element (not a `T[]`/list, and no resolvable alias), the child cannot be typed and this error is raised.","triggerScenarios":"distribute_type_with_meta on BamlValueWithMeta::List where field_type is not a list/array type — e.g. passing an array for a `string` parameter, or an alias that fails to resolve to a list.","commonSituations":"Passing a JSON array where a scalar or class was declared; recursive/alias types that the resolver could not expand into a list; schema refactors that changed `string[]` to `string`.","solutions":["Declare the parameter as a list type (e.g. `string[]`) in the .baml schema so item_type resolves","If the value should be a single item, wrap/unwrap it on the caller side so the shapes match","Check for unresolved or recursive type aliases in the .baml file that prevent item_type from seeing the element type","Read the preceding 'Could not unify ...' context or the field_type to see which declared type rejected the array"],"exampleFix":"// before (.baml)\nfunction Tag(items: string) -> bool { ... }\n// caller sends items: [\"a\", \"b\"]\n\n// after (.baml)\nfunction Tag(items: string[]) -> bool { ... }","handlingStrategy":"validation","validationCode":"function validateListArg(value: unknown, declaredType: string): boolean {\n  return Array.isArray(value) && /^.*\\[\\]$|^list\\s*</.test(declaredType);\n}","typeGuard":"const isList = (v: unknown): v is unknown[] => Array.isArray(v);","tryCatchPattern":null,"preventionTips":["Declare array parameters with `T[]` syntax in .baml","Wrap single items into arrays when the signature expects a list","Resolve recursive type aliases so element types are inferable","Test signatures with sample payloads after edits"],"tags":["rust","type-system","baml","list-type"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}