dataclass#
- class langworks.dsl.constraints.dataclass.Dataclass#
A constraint enforcing a JSON-schema as drawn up from the :py:deco:`dataclasses.dataclass` or
typing.TypedDict
subclass passed. After acquiring generated output, it automatically cast this output to an object of the given class.This constraint may be applied as follows:
``` {% dataclass cls, var = "data" %}. ```
With cls referring to a dataclass or TypedDict as passed to the context.
As subclass of
Constraint
, any of the default arguments may also be passed:``` The answer is {% dataclass cls, var = "data", params = Params(max_tokens = 1) %} ```
Properties#
- spec: DataclassType | TypedDictType = None#
The list of options that the LLM may choose from.
- schema: dict = None#
The class stored in
spec
, but represented as a JSON schema, stored in a Python dict.
- repair: bool = False#
Controls whether any malformed JSON returned by the LLM is (attempted to be) repaired.
Note
This feature requires installation of the json-repair package.
Added in version 0.3.0.