Core
Schema
Base Field
- final class belso.core.schema.BaseField(name, type_, description, required=True, default=None, enum=None, range_=None, exclusive_range=None, length_range=None, items_range=None, properties_range=None, regex=None, multiple_of=None, format_=None)[source]
Bases:
object
A base class for defining fields in a schema.
- default
- description
- enum
- exclusive_range
- format_
- items_range
- length_range
- multiple_of
- name
- properties_range
- range_
- regex
- required
- type_
Array Field
- class belso.core.field.ArrayField(name, items_type=<class 'str'>, description='', required=True, default=None, enum=None, range_=None, exclusive_range=None, length_range=None, items_range=None, properties_range=None, regex=None, multiple_of=None, format_=None)[source]
Bases:
BaseField
BaseField class for arrays of items. Supports all advanced validation parameters passed via BaseField.
OpenAI
Google
Ollama
Anthropic
Mistral
LangChain
HuggingFace
- default
- description
- enum
- exclusive_range
- format_
- items_range
- items_type
- length_range
- multiple_of
- name
- properties_range
- range_
- regex
- required
- type_
Nested Field
- class belso.core.field.NestedField(name, schema, description='', required=True, default=None, enum=None, range_=None, exclusive_range=None, length_range=None, items_range=None, properties_range=None, regex=None, multiple_of=None, format_=None)[source]
Bases:
BaseField
BaseField class for nested schemas. Supports all advanced validation parameters passed via BaseField.
OpenAI
Google
Ollama
Anthropic
Mistral
LangChain
HuggingFace
- default
- description
- enum
- exclusive_range
- format_
- items_range
- length_range
- multiple_of
- name
- properties_range
- range_
- regex
- required
- schema
- type_
Field
- class belso.core.field.Field(name: str, type: Any, description: str = '', required: bool = True, default: Any | None = None, enum: List[Any] | None = None, range: tuple | None = None, exclusive_range: tuple | None = None, length_range: tuple | None = None, items_range: tuple | None = None, properties_range: tuple | None = None, regex: str | None = None, multiple_of: float | None = None, format: str | None = None)[source]
Bases:
object
Factory class that returns the correct
BaseField
subtype (BaseField
,NestedField
, orArrayField
).
SchemaProcessor
- class belso.core.processor.SchemaProcessor[source]
Bases:
object
A unified class for schema processing, including translation and validation. This class combines the functionality of the previous Translator and Validator classes.
- static convert(schema, to, from_format=None)[source]
Convert a schema to a specific format. This method can automatically detect the input schema format and convert it to our internal format before translating to the target format.
Args
schema (
Any
): the schema to conver.to (
str
): the target format. Can be a string or abelso.utils.FORMATS
attribute.from_format (
Optional[str]
): optional format hint for the input schema. IfNone
, the format will be auto-detected. Defaults toNone
.
Returns
Dict[str, Any]
- static detect_format(schema)[source]
Detect the format of a schema.
Args
schema (
Any
): the schema to detect.
Returns
str
: the detected format as a string.
- static display(schema, format_type=None)[source]
Pretty-print a schema using colors and better layout, including nested fields.
Args
schema (
Any
): the schema to print.format_type (
Optional[str]
): format of the schema. Defaults toNone
.
- static load(path, standardize=True)[source]
Load a schema from a file in the specified format.
Args
path (
Union[str, Path]
): the path to the file to load.standardize (
bool
): whether to convert the schema to our internal ‘belso’ format. Defaults toTrue
.
Returns
Any
: the loaded schema.
- static save(schema, path)[source]
Save a schema to a file in the specified format.
Args
schema (
Any
): the schema to save.path (
Union[str, Path]
): the path to save the schema to.
- static standardize(schema, from_format=None)[source]
Convert a schema from a specific format to our internal ‘belso’ format. If from_format is not specified, it will be auto-detected.
Args
schema (
Any
): the schema to convert.from_format (
Optional[str]
): the format of the input schema. IfNone
, the format will be auto-detected. Defaults toNone
.
Returns
Type[belso.Schema]
: the converted belso schema.