json_schema_utils
Convert JSON Schema dicts to Python types.
json_schema_dict_to_dataclass(schema, name=None)
Convert a JSON Schema dict into a dataclass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict
|
The JSON Schema dict to convert to a dataclass |
required |
name
|
Optional[str]
|
The name of the dataclass |
None
|
Returns:
| Type | Description |
|---|---|
type
|
The dataclass |
Source code in outlines/types/json_schema_utils.py
json_schema_dict_to_pydantic(schema, name=None)
Convert a JSON Schema dict into a Pydantic BaseModel class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict
|
The JSON Schema dict to convert to a Pydantic BaseModel |
required |
name
|
Optional[str]
|
The name of the Pydantic BaseModel |
None
|
Returns:
| Type | Description |
|---|---|
type[BaseModel]
|
The Pydantic BaseModel class |
Source code in outlines/types/json_schema_utils.py
json_schema_dict_to_typeddict(schema, name=None)
Convert a JSON Schema dict into a TypedDict class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict
|
The JSON Schema dict to convert to a TypedDict |
required |
name
|
Optional[str]
|
The name of the TypedDict |
None
|
Returns:
| Type | Description |
|---|---|
_TypedDictMeta
|
The TypedDict class |
Source code in outlines/types/json_schema_utils.py
schema_type_to_python(schema, caller_target_type)
Get a Python type from a JSON Schema dict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict
|
The JSON Schema dict to convert to a Python type |
required |
caller_target_type
|
Literal['pydantic', 'typeddict', 'dataclass']
|
The type of the caller |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The Python type |