Formatron v0.4.2
Formatron empowers everyone to control the output format of language models with minimal overhead.
Loading...
Searching...
No Matches
schema.py
Go to the documentation of this file.
1"""
2This module contains the Schema abstract class and FieldInfo abstract class.
3"""
4import abc
5import typing
6
7
8class FieldInfo(abc.ABC):
9 @property
10 @abc.abstractmethod
11 def annotation(self) -> typing.Type[typing.Any] | None:
12 """
13 Get the type annotation of the field.
14 """
15 pass
16
17 @property
18 @abc.abstractmethod
19 def required(self) -> bool:
20 """
21 Check if the field is required for the schema.
22 """
23 pass
24
25
26class Schema(abc.ABC):
27 """
28 An abstract schema that describes some data.
29 """
30 @classmethod
31 @abc.abstractmethod
32 def fields(cls) -> dict[str, FieldInfo]:
33 """
34 Get the fields of the schema.
35 """
36 pass
37
38 @classmethod
39 @abc.abstractmethod
40 def from_json(cls, json: str) -> "Schema":
41 """
42 Create a schema from a JSON string.
43 """
44 pass
typing.Type[typing.Any]|None annotation(self)
Get the type annotation of the field.
Definition schema.py:22
bool required(self)
Check if the field is required for the schema.
Definition schema.py:39