# `Puck.Backends.Baml.TypeBuilder`
[🔗](https://github.com/bradleygolden/puck/blob/v0.2.25/lib/puck/backends/baml/type_builder.ex#L2)

Converts Zoi schemas to `BamlElixir.TypeBuilder` structs.

When using the BAML backend with `output_schema`, Zoi schemas define the
expected output structure but BAML's Rust runtime has no knowledge of these
types. This module bridges the gap by converting Zoi schemas into
`BamlElixir.TypeBuilder` structs that can be passed as the `:tb` option,
giving BAML full knowledge of the schema for Schema-Aligned Parsing and
prompt formatting via `ctx.output_format`.

## Pipeline

1. Normalize struct schemas to object schemas (structs can't be JSON encoded)
2. Convert to JSON Schema via `Zoi.to_json_schema/1`
3. Recursively convert JSON Schema nodes to TypeBuilder structs

## Examples

    iex> schema = Zoi.object(%{name: Zoi.string(), age: Zoi.integer()})
    iex> types = Puck.Backends.Baml.TypeBuilder.from_schema(schema)
    iex> [%BamlElixir.TypeBuilder.Class{name: "DynamicOutput"}] = types

# `from_dynamic_union`

Builds TypeBuilder structs for a union schema with dynamic classes.

When a union schema has runtime-declared dynamic classes, this function
emits a `TB.Enum` for the type discriminator (with per-value descriptions)
and a `TB.Class` for the shared dynamic fields. Non-type fields are collected
from all dynamic schemas and emitted as `string | null` unions.

Returns a flat list of `TB.Enum` and `TB.Class` structs.

# `from_schema`

Converts a Zoi schema to a list of `BamlElixir.TypeBuilder` structs.

Returns a list of named types (classes, enums) that BAML's Rust runtime
needs to know about. Inline types (lists, maps, unions, literals) are
embedded directly in field type references.

## Options

  * `:name` - Type name prefix for generated classes and enums (default: `"DynamicOutput"`)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
