BoundaryML/baml · error
Invalid type value
Error message
Invalid type value
What it means
An expect("Invalid type value") panic in parse_base_type. The code first string-matches the identifier against known primitive names (string, int, float, bool, image, audio, pdf, video) and then calls TypeValue::from_str(...).expect(...), assuming from_str cannot fail for those names. If the match arms and TypeValue::from_str ever disagree (new alias added to one but not the other), the expect panics.
Source
Thrown at engine/baml-lib/ast/src/parser/parse_types.rs:173
));
// Return a Symbol type to allow type validation to continue
// This will trigger the "type not found" error in the validation pipeline
Some(FieldType::Symbol(
FieldArity::Required,
Identifier::Local(
current.as_str().to_string(),
diagnostics.span(current.as_span()),
),
None,
))
}
Rule::identifier => {
let identifier = parse_identifier(current.clone(), diagnostics);
let field_type = match current.as_str() {
"string" | "int" | "float" | "bool" | "image" | "audio" | "pdf" | "video" => {
FieldType::Primitive(
FieldArity::Required,
TypeValue::from_str(identifier.name()).expect("Invalid type value"),
diagnostics.span(current.as_span()),
None,
)
}
"null" => FieldType::Primitive(
FieldArity::Optional,
TypeValue::Null,
diagnostics.span(current.as_span()),
None,
),
"true" => FieldType::Literal(
FieldArity::Required,
LiteralValue::Bool(true),
diagnostics.span(current.as_span()),
None,
),
"false" => FieldType::Literal(
FieldArity::Required,View on GitHub (pinned to bd85ce9dee)
Solutions
- Use a standard BAML primitive type name in your .bml file (string, int, float, bool, image, audio, pdf, video) at the reported span
- Check for case sensitivity: `String` vs `string` — use the lowercase canonical form
- Report the input upstream if a documented type name panics — the match list and TypeValue::from_str are out of sync
- When adding primitives, update both the match arms in parse_base_type and TypeValue::from_str together
Example fix
// before field String // after field string
Defensive patterns
Strategy: validation
Validate before calling
const PRIMITIVES: &[&str] = &["string","int","float","bool","image","audio","pdf","video"];
fn is_known_primitive(t: &str) -> bool {
PRIMITIVES.contains(&t.trim())
}
// call before referencing the type in .bml or invoking the parser Type guard
fn as_type_value(t: &str) -> Option<&str> {
match t.trim() {
"string" | "int" | "float" | "bool" | "image" | "audio" | "pdf" | "video" => Some(t.trim()),
_ => None,
}
} Try / catch
std::panic::catch_unwind(|| parse_base_type(pair, &mut diagnostics))
.map_err(|_| diagnostics.push("primitive name not recognized by TypeValue::from_str")); Prevention
- Use exact lowercase primitive names: string, int, float, bool, image, audio, pdf, video
- Update the match list in parse_base_type and TypeValue::from_str together when adding primitives
- Route unknown type names to a diagnostic (FieldType::Identifier) rather than expect
- Add a unit test asserting every match-list literal round-trips through TypeValue::from_str
When it happens
Trigger: parse_base_type parsing a Rule::identifier whose string is in the primitive match list but not recognized by TypeValue::from_str — i.e. drift between the literal match list and the TypeValue enum's FromStr impl. Not reachable from valid .bml input with matched lists.
Common situations: Hit during BAML development when adding a new primitive type to the match arms without updating TypeValue::from_str (or vice versa), or when case-sensitivity changes make the same literal parse differently.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Name should always be defined for attribute.
- Encountered impossible doc comment during parsing: {:?}, {:?
- c_for_init_stmt cannot accept empty input
- c_for_after_stmt cannot accept empty input
- block aware tail expression is not empty
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/a3df2d44036fe3c5.
Report an issue: GitHub.