yera.dsl.struct

The base class for structured-generation specs.

Subclass Struct to define the shape of a value you want the LLM to produce, then call Struct.fill to generate an instance from a prompt.

Symbols

class Struct — Base class for structured-generation specs.

Struct

Inherits: PydanticBaseModel

Base class for structured-generation specs.

Subclass Struct to declare the shape of a value the LLM should produce, then call fill on the subclass to generate a populated instance from a prompt.

Unknown fields are rejected at construction time: structs are intended to be fixed in structure, separating data (the struct) from behaviour (defined elsewhere). Passing fields not declared on the subclass raises a ValidationError.

Examples

class Person(Struct):
    name: str
    age: int
    occupation: str

bio = "Dr. John Smith is a 36-year-old data scientist."

Person.fill(bio)
Person(name='John Smith', age=36, occupation='data scientist')

Methods

fill — Generate an instance of this struct from a prompt.
__hash__ — Hash by field values, recursively freezing containers.

Struct.fill

fill(
    prompt: str,
    **kwargs,
) → Self

Generate an instance of this struct from a prompt.

Sends the prompt to the active LLM and parses its response into an instance of the calling subclass.

Parameters

prompt
type: str

The user-message prompt describing what to generate.

**kwargs
type: str | int | float | bool

Additional options forwarded to the underlying LLM (e.g. provider-specific generation parameters).

Returns

type: Self

An instance of the calling subclass, populated from the LLM's response.

Struct.__hash__

__hash__() → int

Hash by field values, recursively freezing containers.

Allows Struct instances to be used as members in hashable containers and as dict keys. Mutating fields after hashing will make the instance unfindable in the collection; treat hashed structs as immutable.