-
Notifications
You must be signed in to change notification settings - Fork 341
Open
Description
Product
BAML
Describe the bug
In the Go client, when using the BAML ClientRegistry to define an LLM client on the fly, BAML's internal serialization panics if the options parameter contains a nested map:
// ...
clientOptions := map[string]any{
"api_key": apiKey,
"model": "claude-haiku-4-5-20251001",
"metadata": map[string]any{
"user_id": "some-metadata",
},
}
clientRegistry := baml.NewClientRegistry()
clientRegistry.AddLlmClient("example", "anthropic", clientOptions)
clientRegistry.SetPrimaryClient("example")
result, err := b.ExtractResume(
ctx,
"...",
b.WithClientRegistry(clientRegistry),
)
if err != nil {
panic(err)
}
// ...panic: encoding client registry: encoding client options: encoding client options field 'metadata': interface does not implement InternalBamlSerializer
goroutine 1 [running]:
github.com/invakid404/baml-client-options-serialization-issue/baml_client.ExtractResume({0x10055fc60, 0x100828100}, {0x10040c625, 0x8e}, {0x14000039ed0, 0x1, 0x1400012e000?})
/Users/inva/Coding/baml-client-options-serialization-issue/baml_client/functions.go:54 +0x550
main.runTest(0x1400012c000)
/Users/inva/Coding/baml-client-options-serialization-issue/main.go:19 +0x15c
main.main()
/Users/inva/Coding/baml-client-options-serialization-issue/main.go:51 +0x250
exit status 2
My brief investigation revealed that, for nested maps' values, the reflect package reports kind: reflect.Interface, which puts us in this branch. If the serialization logic had peeked at the .Elem() of the reflect value, the kind would've been correctly reported as reflect.String.
Reproduction Steps
Minimal reproducible example: https://github.com/invakid404/baml-client-options-serialization-issue
BAML Version
0.214.0
Language/Framework
Go
LLM Provider
None
LLM Model
No response
Operating System
macOS
Browser
None
Code Editor
None
Metadata
Metadata
Assignees
Labels
No labels