Formatron v0.4.2
Formatron empowers everyone to control the output format of language models with minimal overhead.
|
This module contains utilities for creating schemas from JSON schemas. More...
Classes | |
class | FieldInfo |
Functions | |
schemas.schema.Schema | create_schema (dict[str, typing.Any] schema, registry=Registry()) |
Create a Schema object from a JSON schema object. | |
str | _resolve_new_url (str uri, str ref) |
Adapted from https://github.com/python-jsonschema/referencing/blob/main/referencing/_core.py#L667. | |
None | _validate_json_schema (dict[str, typing.Any] schema) |
typing.Type | _convert_json_schema_to_our_schema (dict[str, typing.Any] schema, dict[int, typing.Type] json_schema_id_to_schema) |
Recursively handle all types needed to fully determine the type of a schema. | |
_extract_fields_from_object_type (typing.Type object_type) | |
typing.Type[typing.Any|None] | _infer_type (dict[str, typing.Any] schema, dict[int, typing.Type] json_schema_id_to_schema) |
Infer more specific types. | |
typing.Any | _get_literal (dict[str, typing.Any] schema) |
typing.Type | _handle_literal (typing.Any literal, typing.Type obtained_type, dict[str, typing.Any] schema, dict[int, typing.Type] json_schema_id_to_schema) |
typing.Type | _create_custom_type (typing.Type|None obtained_type, dict[str, typing.Any] schema, dict[int, typing.Type] json_schema_id_to_schema) |
typing.Type[typing.Any|None] | _obtain_type (dict[str, typing.Any] schema, dict[int, typing.Type] json_schema_id_to_schema) |
Directly obtain type information from this schema level. | |
_merge_referenced_schema (dict[str, typing.Any] schema, set[int] memo) | |
_merge_key (dict[str, typing.Any] schema, str ref_key, typing.Any reference_value) | |
_recursive_resolve_reference (str base_uri, typing.Any schema, Registry registry, set[int] memo) | |
_resolve_reference (dict[str, typing.Any] schema, str key, typing.Any resolver) | |
Variables | |
int | _counter |
This module contains utilities for creating schemas from JSON schemas.
|
protected |
Recursively handle all types needed to fully determine the type of a schema.
Definition at line 140 of file json_schema.py.
|
protected |
Definition at line 193 of file json_schema.py.
|
protected |
Definition at line 157 of file json_schema.py.
|
protected |
Definition at line 180 of file json_schema.py.
|
protected |
Definition at line 185 of file json_schema.py.
|
protected |
Infer more specific types.
Definition at line 169 of file json_schema.py.
|
protected |
Definition at line 273 of file json_schema.py.
|
protected |
Definition at line 254 of file json_schema.py.
|
protected |
Directly obtain type information from this schema level.
Definition at line 216 of file json_schema.py.
|
protected |
Definition at line 292 of file json_schema.py.
|
protected |
Adapted from https://github.com/python-jsonschema/referencing/blob/main/referencing/_core.py#L667.
Definition at line 125 of file json_schema.py.
|
protected |
Definition at line 314 of file json_schema.py.
|
protected |
Definition at line 130 of file json_schema.py.
schemas.schema.Schema formatron.schemas.json_schema.create_schema | ( | dict[str, typing.Any] | schema, |
registry = Registry() ) |
Create a Schema object from a JSON schema object.
This function takes a JSON schema and converts it into a Schema object that can be used for data validation and serialization. Currently, only the following JSON Schema features are supported:
type
keyworditems
keywordproperties
keywordadditionalProperties
is false.enum
and const
keywordenum
(or const
) and type
are present, type
will be ignored.required
keyword$defs
, $id
, $anchor
, $dynamicAnchor
) are supported.schema | A dictionary representing a valid JSON schema. |
registry | A Registry object containing additional schema definitions. Defaults to an empty Registry. |
jsonschema | If the input schema is not a valid JSON Schema. |
ValueError | If there are issues with schema references, constraints or requirements. |
Definition at line 107 of file json_schema.py.
|
protected |
Definition at line 67 of file json_schema.py.