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
Struct
PydanticBaseModelBase 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
Struct.fill
fill(
prompt: str,
**kwargs,
) → SelfGenerate 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
The user-message prompt describing what to generate.
Additional options forwarded to the underlying LLM (e.g. provider-specific generation parameters).
Returns
An instance of the calling subclass, populated from the LLM's response.
Struct.__hash__
__hash__() → intHash 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.