BoundaryML/baml · error
Encountered impossible config map key during parsing
Error message
Encountered impossible config map key during parsing
What it means
This is a `unreachable!()` panic from the infix-operator mapping in `parse_expression`'s pratt parser in the BAML AST parser. The match enumerates every binary operator rule the grammar allows (EQ, NEQ, comparisons, arithmetic, BIT_XOR, BIT_SHL/SHR, OR, AND, INSTANCE_OF, etc.); receiving any other rule as an infix operator breaks the grammar/parser contract and panics. It is an internal invariant, typically triggered only by grammar/code version mismatch.
Source
Thrown at engine/baml-lib/ast/src/parser/parse_expression.rs:533
fn parse_config_map_key(token: Pair<'_>, diagnostics: &mut Diagnostics) -> Expression {
assert_correct_parser(&token, &[Rule::config_map_key], diagnostics);
let span = diagnostics.span(token.as_span());
if let Some(current) = token.into_inner().next() {
return match current.as_rule() {
Rule::identifier => Expression::Identifier(parse_identifier(current, diagnostics)),
Rule::quoted_string_literal => Expression::StringValue(
current.into_inner().next().unwrap().as_str().to_string(),
span,
),
_ => {
unreachable_rule(¤t, "config_map_key", diagnostics);
Expression::Identifier(Identifier::Local(String::new(), span))
}
};
}
unreachable!("Encountered impossible config map key during parsing")
}
pub(super) fn parse_raw_string(token: Pair<'_>, diagnostics: &mut Diagnostics) -> RawString {
assert_correct_parser(&token, &[Rule::raw_string_literal], diagnostics);
let mut content = None;
for current in token.into_inner() {
match current.as_rule() {
Rule::raw_string_literal_content_1
| Rule::raw_string_literal_content_2
| Rule::raw_string_literal_content_3
| Rule::raw_string_literal_content_4
| Rule::raw_string_literal_content_5 => {
content = Some((
current.as_str().to_string(),
diagnostics.span(current.as_span()),
));View on GitHub (pinned to bd85ce9dee)
Solutions
- Rewrite the BAML expression using only supported binary operators (==, !=, <, >, +, -, *, /, &&, ||, instanceof, etc.)
- If you added a new infix operator to baml.pest, add the corresponding arm (e.g. `Rule::COALESCE => BinaryOperator::Coalesce`) in the `map_infix` match
- Align grammar and parser versions by upgrading/downgrading BAML
Example fix
// before (unsupported operator)
let v = a ?? b;
// after
let v = if a != null { a } else { b }; Defensive patterns
Strategy: validation
Validate before calling
// Restrict generated BAML to known binary operators:
const SUPPORTED_INFIX = ['==','!=','<','>','<=','>=','+','-','*','/','%','&&','||','&','|','^','<<','>>','instanceof'];
function assertSupportedBinaryOps(expr) {
for (const op of SUPPORTED_INFIX) { /* tokenizer-level check */ }
if (/\?\?|->|\|>|~/.test(expr)) {
throw new Error('Unsupported infix operator will panic the BAML parser: ' + expr);
}
} Type guard
const usesOnlySupportedInfix = (expr) => !/\?\?|\|>|::/.test(expr);
Try / catch
catch (panicOutput) {
if (String(panicOutput).includes('Unexpected infix operator')) {
logParserBug('grammar added an infix op missing from map_infix', panicOutput);
return null;
}
throw panicOutput;
} Prevention
- Use only the documented BAML binary operators in expressions
- Add the map_infix arm in the same PR that adds a binary operator to baml.pest
- Version-align grammar and parser crates
- Include every binary operator in parser snapshot tests
When it happens
Trigger: The pratt parser's `map_infix` receives an operator Pair whose rule is not one of the mapped `Rule::*` binary operators — only possible after adding a new binary operator to baml.pest (e.g. `??`, pipeline `|>`) without adding a match arm.
Common situations: Using a newly introduced binary operator in BAML expressions against an older parser; contributors extending the binary-operator grammar without updating `parse_expression`; running mixed-version baml grammar and parser crates.
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/b0194ba4586d05cf.
Report an issue: GitHub.