Formatron v0.4.9
Formatron empowers everyone to control the output format of language models with minimal overhead.
Loading...
Searching...
No Matches
formatron.schemas.dict_inference Namespace Reference

This module contains utilities for inferring schemas from dictionaries. More...

Classes

class  FieldInfo
 

Functions

Type[Any] _infer_type (Any value)
 
typing.Type[schemas.schema.Schemainfer_mapping (collections.abc.Mapping[str, Any] mapping)
 Recursively infer a schema from a mapping.
 

Detailed Description

This module contains utilities for inferring schemas from dictionaries.

Function Documentation

◆ _infer_type()

Type[Any] formatron.schemas.dict_inference._infer_type ( Any value)
protected

Definition at line 59 of file dict_inference.py.

◆ infer_mapping()

typing.Type[schemas.schema.Schema] formatron.schemas.dict_inference.infer_mapping ( collections.abc.Mapping[str, Any] mapping)

Recursively infer a schema from a mapping.

Types that are specially handled:

  • collections.abc.Mapping: converted to a schema. Keys are converted to field names and corresponding value types are converted to field types.
  • collections.abc.Sequence with heterogeneous elements: all different element types are included in a union type.

Other types are directly inferred from the type of the value with no special handling.

Definition at line 95 of file dict_inference.py.