https://www.boundaryml.com logo
🟑 Question about BAML type builder and dynamic cl...
# questions
i
is the BAML type builder supposed to support definining dynamic classes that reference each other at runtime?
for context, I'm using the Go TypeBuilder API to dynamically create classes at runtime; here's a synthetic example of what I'm trying to do:
Copy code
go
// Create Location class
locationBuilder, _ := tb.AddClass("Location")
locationBuilder.AddProperty("street", tb.String())
locationBuilder.AddProperty("city", tb.String())

// Add property to DynamicOutput that references Location
dynamicOutputBuilder, _ := tb.DynamicOutput() // existing @@dynamic class
locationType, _ := locationBuilder.Type()
dynamicOutputBuilder.AddProperty("location", locationType)
The schema sent to the LLM appears to be correct, and the LLM correctly returns a JSON object that matches the schema: { base_field: string, location: { city: string, street: string, }, } But parsing fails with: DistributeTypeWithMetaFailure(Class Location not found)
v
It should def work. I know a few folks that do this. I’ll dig in
i
I have more information now, turns out the issue happens when using the stream API specifically I have a reproduction repo: https://github.com/invakid404/baml-dynamic-class-repro
the non-streaming call works just fine but the streaming one fails with the exact error from my original message
v
ah yes... thats because during streaming your
Location
class looks like this:
Copy code
class Location {
  street string | null
  city string | null
}
and then the value:
Copy code
{}
can successfully be cast to:
Copy code
{
  street: null,
  city: null,
}
but are you saying in go, you're not getting the fields
street
and
city
?
if so thats def a bug!
i
Copy code
2026-01-27T17:11:42.669 [BAML INFO] Found valid cached BAML library path="/Users/inva/Library/Caches/baml/libs/0.218.0/libbaml_cffi-aarch64-apple-darwin.dylib"
2026-01-27T17:11:42.675 [BAML INFO] BAML (v0.218.0) loaded
=== Non-Streaming Example ===
2026-01-27T17:11:45.766 [BAML INFO] Function ExtractInfo:
    Client: Claude (claude-haiku-4-5-20251001) - 3039ms. StopReason: end_turn. Tokens(in/out): 67/51
    ---PROMPT---
    user: Extract structured information from the following text.
    
    John lives at 123 Main Street in San Francisco
    
    Answer in JSON using this schema:
    {
      base_field: string,
      location: {
        street: string,
        city: string,
      },
    }
    
    ---LLM REPLY---
    json
    {
      "base_field": "John lives",
      "location": {
        "street": "123 Main Street",
        "city": "San Francisco"
      }
    }
    
    ---Parsed Response (class DynamicOutput)---
    {
      "base_field": "John lives",
      "location": {
        "street": "123 Main Street",
        "city": "San Francisco"
      }
    }
Result: {Base_field:John lives DynamicProperties:map[location:{Name:Location Fields:map[city:San Francisco street:123 Main Street]}]}
Base Field: John lives
Dynamic Properties: map[location:{Name:Location Fields:map[city:San Francisco street:123 Main Street]}]

=== Streaming Example ===
Partial: &{Base_field:<nil> DynamicProperties:map[location:<nil>]}
2026/01/27 17:11:46 Stream error: Parsing error: Failed to parse LLM response: DistributeTypeWithMetaFailure(Class Location not found)
Prompt: user: Extract structured information from the following text.

Jane lives at 456 Oak Avenue in Los Angeles

Answer in JSON using this schema:
{
  base_field: string,
  location: {
    street: string,
    city: string,
  },
}

Raw Response: json
{
  "base_field": "Jane",
  "location": {
    "street": "456 Oak Avenue",
    "city": "Los Angeles"
  }
}


Detailed message: Parsing error: Failed to parse LLM response: DistributeTypeWithMetaFailure(Class Location not found)
Prompt: user: Extract structured information from the following text.

Jane lives at 456 Oak Avenue in Los Angeles

Answer in JSON using this schema:
{
  base_field: string,
  location: {
    street: string,
    city: string,
  },
}

Raw Response: json
{
  "base_field": "Jane",
  "location": {
    "street": "456 Oak Avenue",
    "city": "Los Angeles"
  }
}

exit status 1
here's what happens exactly
works just fine with the regular call, but when using the stream API, i get a parsing error even though the LLM appears to respond correctly
v
oh isee, yea we should patch this! thanks for sharing this. I'll cc @greg (BAML) who might take this on for a friday project this week!
g
Thanks for the report! Yes, I'll take this on this week.
i
hey, apologies for the ping, but were you able to get to this?
g
Pings are always very welcome! I haven’t closed it out yet but am still expecting to have it prior to the upcoming release.