json_schema_utils
build_strict_schema(json_schema, schema_id)
Performs a series of post-processing steps to ensure a JSON schema is compatible with LLMs.
- Adds the
$id
and$schema
keys. - Sets
additionalProperties
toFalse
for objects without this key. - Resolves
$ref
s and removes$defs
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
json_schema
|
dict
|
The JSON schema to ensure is strict. |
required |
schema_id
|
str
|
The ID of the schema. |
required |
Returns: The strict JSON schema.
Source code in griptape/utils/json_schema_utils.py
resolve_refs(schema)
Recursively resolve all local $refs in the given JSON Schema using $defs as the source.
Required since pydantic does not support nested schemas without $refs. https://github.com/pydantic/pydantic/issues/889
Parameters:
Name | Type | Description | Default |
---|---|---|---|
schema
|
dict[str, Any]
|
A JSON Schema as a dictionary, which may contain "$refs" and "$defs". |
required |
Returns: A new dictionary with all local $refs resolved against $defs.