Skip to Workarounds

Problem

BAMLs parser is a blackbox that is hard to understand, so sometimes it does things that look off to the user and can take quite a while to explain / understand. Without knowledge of the parser, a user can be completely lost about what is happening. One of the most prevalent issues of this is with array parsing.

When parsing an array of malformed objects, BAML has made the decision to drop elements that don’t fit.

[{
  "name": "Vaibhav",
  "number": 123456
}]
// assuming Model.number must be less than 10
// will parse as:
[]

More nuanced situations can be:

[
  {
    foo: bar,
    required_field: value,
  },
  {
    foo: bar2
    // missing required_field
  }
]
[
  {
    "foo": "bar",
    "required_field": "value"
  }
  // second item gets dropped
]

There are 3 specific problems here:

  1. Problem 1: During the prompt iteration loop, its difficult for a user to quickly identify WHEN elements are dropped (imagine 10 items created, 2 dropped)
  2. Problem 2: During the prompt iteration loop, once identified, its difficult for a user to understand WHY the element was dropped
  3. Problem 3: During the application loop (in my business logic), its impossible to identify WHEN an element has been dropped

Why do each of those problems matter:

Problems 1 and 2 affect the same thing: if i’m able to quickly understand WHEN and WHY, then i can update my prompts and data models to minimize that, or perhaps even detect that.

How might I improve my schema

I may choose to use more forgiving types: @check instead of @assert , or allow for nullable values.

Instead of choosing: NonGamilEmail[] I might prefer for: (NonGmailEmail?)[] so unparseable values become nulled out instead of dropped.