https://www.boundaryml.com logo
Help with BAML coerce error
# help
k
Hi BAML! I have a LLM response that is encountering a BAML coerce error. My guess would be the triple backticks with brackets causing the error. (I'll include the LLM response in the thread, couldnt fit it in this message) I'm not sure if this is a bug on BAML's end or if i'm not using BAML correctly. Appreciate any help/advice. Thank you! Truncated error message to fit in this message
Copy code
BAML COERCE ERROR:
Failed to coerce value: ParsingError { scope: [], reason: "Failed to find any ExtractedLiterals @stream.not_null in 4 items", causes: [ParsingError { scope: [], reason: "Failed to find any ExtractedLiterals @stream.not_null in 3 items", causes: [ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] },
...
 causes: [] }] }] }, ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }] }
Here is the raw llm response I'll analyze the parser systematically, tracing each literal string used in matching/validation logic. ## Analysis ### Structure Detection The parser splits on
' - '
and checks
parts[1].strip() == 'aaaaaa'
to detect the optional logger field. -
' - '
— delimiter used in
split()
and rejoin; required as the field separator -
'aaaaaa'
— exact match on `parts[1]`; triggers the 6-part path but is optional (the 5-part path without it also succeeds) ### Timestamp Extraction (
extract_timestamp
)
Copy code
python
pattern = r'^(\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\s+[+-]\d{4})'
- All components are regex patterns (digit groups, whitespace, character classes) — no literal strings here, only patterns. ### Timestamp Validation (
validate_timestamp
)
Copy code
python
r'^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}:\d{2}(\s*(Z|[+-]\d{2}:?\d{2}))?$'
r'^\d{10,13}$'
###
validate_logger
Copy code
python
return value == "aaaaaa"
-
"aaaaaa"
— only checked when
has_logger
is
True
, which itself required
parts[1].strip() == 'aaaaaa'
. So
aaaaaa
is optional (its absence is the no-logger path). ###
validate_level
Copy code
python
return value == "WARNING"
-
"WARNING"
— this is a required field ### Field Assignments (repository, sensor, message) These are validated only for being non-empty strings — no literal content required. ### Summary of Literal Roles | Literal | Role | Required? | |---|---|---| |
' - '
| Field delimiter (split + rejoin) | Yes — without it, no valid segmentation | |
'AAAAAA'
| Exact match for
level
field | Yes —
validate_level
raises on mismatch | |
'aaaaaa'
| Exact match for optional
logger
field | No — absent logger path is valid |
Copy code
json
{
  "required_literals": [
    " - ",
    "AAAAAA"
  ],
  "optional_literals": [
    "aaaaaa"
  ],
  "explanation": "The [Truncated] log."
}
here is the error message split into 2 messages
Copy code
BAML COERCE ERROR:
Failed to coerce value: ParsingError { scope: [], reason: "Failed to find any ExtractedLiterals @stream.not_null in 4 items", causes: [ParsingError { scope: [], reason: "Failed to find any ExtractedLiterals @stream.not_null in 3 items", causes: [ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }, ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }, ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }] }, ParsingError { scope: [], reason: "Failed to find any ExtractedLiterals @stream.not_null in 4 items", causes: [ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }, ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] },
Copy code
ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }, ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }] }, ParsingError { scope: [], reason: "Failed to find any ExtractedLiterals @stream.not_null in 4 items", causes: [ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }, ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }, ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }, ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }] }, ParsingError { scope: [], reason: "Failed while parsing required fields: missing=1, unparsed=0", causes: [ParsingError { scope: [], reason: "Missing required field: explanation", causes: [] }] }] }
v
can you post the raw string in a code-block or as a file?
Copy code
<block>
k
good idea, i'll upload a file
b
Can you also share the baml class you’re trying to parse as?
k
Here you go, thanks again!
Copy code
class ExtractedLiterals {
  required_literals string[] @description("List of literal strings that must exist in the log for parsing to succeed")
  optional_literals string[] @description("List of literal strings that may exist in the log but are not required for parsing to succeed")
  explanation string @description("Brief explanation of the analysis")
}
a
@Kai (BAML) will take a look tomorrow!
sorry for the delay
k
@aaronv (BAML) no worries, appreciate the help!
j
I have a failing golang test of this error with test data. let me know the best way to share it with you
a
We did manage to resolve this -- will release this: https://github.com/BoundaryML/baml/commit/01ce9e3d6bd46aee0aeb32b4382a8bbb32e7775f working on a release now
j
great! let us know when the release is out and will be sure to test it
2 Views