json#
- class langworks.dsl.constraints.json.JSON#
A constraint specifying a JSON-schema that the LLM must conform to during generation. They may be embedded in queries as follows:
``` Ada Lovelace's personal profile can be represented in JSON as follows: {% json %} { "title": "Profile", "type": "object", "properties": { "first_name": { "title": "First name", "type": "string" }, "last_name": { "title": "Last name", "type: "string } }, "required": ["first_name", "last_name"] } {% endjson %}. ```
Additional constraints may be passed:
``` {% json var = "profile", params = Params(temperature = 0.0) %}...{% endjson %} ```
Properties#
- spec: dict = None#
The JSON schema that specifies the constraint.
- 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.