Usage Guide¶
Load a schema from JSON text¶
from ie_schema import IESchema
schema = IESchema.loads(
"""
{
"entities": ["gene", "disease"],
"relations": [
{"associated_with": {"head": "gene", "tail": "disease"}}
]
}
"""
)
Load from a JSON Schema string¶
The same IESchema.loads accepts a root JSON Schema object as a string (for example from another tool or hand-written draft). Top-level keys must not match unknown IE ingest fields: native IE JSON rejects unknown top-level keys, so a document with type / properties is treated as JSON Schema, not as an empty IE schema.
from ie_schema import IESchema
schema = IESchema.loads(
'{"type":"object","properties":{"title":{"type":"string"},"count":{"type":"integer"}}}'
)
Load from dataclass or Pydantic model¶
IESchema.loads also accepts a stdlib dataclass / Pydantic v2 BaseModel class (or instance).
Install the optional dependency first:
uv add 'ie_schema[model]'
from dataclasses import dataclass
from ie_schema import IESchema
@dataclass
class BusinessRecord:
business_name: str
score: float
schema = IESchema.loads(BusinessRecord)
Load a schema from disk¶
schema = IESchema.load("schema.json")
Iterate planned tasks¶
IESchema is iterable and yields task objects for classification, entity extraction, relation extraction, and structure extraction.
for task in schema:
print(type(task).__name__)
Render prompt debug string¶
print(schema.prompt())