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
BaseModelConditionBase 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.__init_subclass__
__init_subclass__(
expects_result: bool = False,
**kwargs,
) → NoneInitialise subclass with an expects result field populated.
Struct.expects_result
expects_result() → boolReturn whether this struct expects an LLM result.
Struct.get_tool_name
get_tool_name() → strReturn the tool name (class name) used when calling the LLM.
Struct.get_call_id
get_call_id() → strReturn the stored tool call ID, or raise if unset.
Returns
The call ID string assigned via set_call_id.
Raises
If no call ID has been set (__call_id__ is None).
Struct.set_call_id
set_call_id(
call_id: str,
) → NoneSet the tool call ID for this struct instance.
Parameters
String identifier assigned by the LLM tool-calling API.
Struct.fill
fill(
instruction: str | None = None,
on_wire: bool = False,
**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
extra prompt instruction to inform struct generation.
whether the llm text output from this fill is included back in the context.
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.form
form(
label: str | None = None,
) → SelfAsk the user to fill in this struct as a form.
Each field is presented with a widget suited to its type. Submissions that fail validation are shown again with their errors until one is valid.
Parameters
Optional question shown above the form.
Returns
An instance of the calling subclass built from the accepted submission.
Examples
class Deploy(Struct):
service: str
replicas: int = 1
Deploy.form("Deploy which service?")
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.
Struct.model_json_schema
model_json_schema(
by_alias: bool = True,
ref_template: str = DEFAULT_REF_TEMPLATE,
schema_generator: type[GenerateJsonSchema] = _StrictSchema,
mode: JsonSchemaMode = 'validation',
union_format: Literal['any_of', 'primitive_type_array'] = 'any_of',
) → dictReturn the JSON schema for this struct with extra strictness applied.
Overridden to ensure all nested objects have additionalProperties: false.
Returns
A JSON schema dict with additionalProperties: false for all objects.