Formatron
v0.4.2
v0.4.2
v0.4.1
v0.4.0
v0.3.4
v0.3.3
v0.3.2
v0.3.1
v0.3.0
v0.2.0
v0.1.3
v0.1.2
v0.1.1
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
"""
2
This module contains the Schema abstract class and FieldInfo abstract class.
3
"""
4
import
abc
5
import
typing
6
7
8
class
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
26
class
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
formatron.schemas.schema.FieldInfo
Definition
schema.py:9
formatron.schemas.schema.FieldInfo.annotation
typing.Type[typing.Any]|None annotation(self)
Get the type annotation of the field.
Definition
schema.py:22
formatron.schemas.schema.FieldInfo.required
bool required(self)
Check if the field is required for the schema.
Definition
schema.py:39
src
formatron
schemas
schema.py
Generated by
1.11.0