String literals do not decode \\xHH / \\uHHHH escapes (kept raw)
Summary
BAML string literals do not decode hex (\\\xHH) or unicode (\\\uHHHH) escape sequences — the backslash bytes are kept raw. They survive lexing, Display, Debug, as_str(), len(), and JSON serialization, so a literal containing a control char measures longer than the string it denotes and never equals the intended value.
Minimal repro
In any .baml file evaluated through the Rust runtime:
test control_chars {
len("a\x1bb") == 3
len("a\u0041b") == 3
}Observed on toolchain 0.17.0: both asserts fail — lengths come back 5 and 8 (raw bytes kept). Only \\n-class escapes from the escape table decode.
Impact
Any prompt/template embedding control characters (notably \x1b for terminal styling) via literals gets the wrong string at runtime with no error. Downstream workaround in the wild: hand-encoding affected bytes as raw UTF-8 in literals plus length asserts, with a note to revert once the escapes land.
Expected
"a\x1bb" denotes a 3-char string; "a\u0041b" denotes a 3-char string equal to "aaab". At minimum, document the supported escape set if hex/unicode are intentionally out of scope.
Environment
baml wrapper 0.2.4, toolchain 0.17.0 (canary), macOS arm64.
Source: BoundaryML/baml