schemacast.cast¶
Cast episodes into a governed schema: the whole pipeline.
Per episode: select a slice → one extraction call → validate → at most two
typed repairs → quarantine what still fails → a record graph (graflo
RecordGraph, quotes and spans in evidence). The batch's record graphs
are then resolved by graflo, without a model and without a
database: what their keys identify becomes output, the rest is staged. A
write resolves them again against the database (schemacast.write).
No critic pass: a valid extraction is never judged a second time.
An episode that produces nothing is quarantined and the run goes on; so is one
whose request fails at the provider (provider_error), whose reply stops at
the output limit (truncated) or that the model refuses (refused). A
fault in the deployment — no key, a refused configuration, a cache miss while
replaying — stops the run, because every other episode would fail the same way.
Attributes¶
EPISODE_FAULTS = (LLMReplyError, LLMRequestTimeoutError, APIError)
module-attribute
¶
EpisodeStatus = Literal['ok', 'partial', 'failed']
module-attribute
¶
MAX_REPAIRS = 2
module-attribute
¶
OUTPUT_FORMAT_VERSION = 6
module-attribute
¶
Classes¶
CastResult
¶
Bases: BaseModel
The output of a cast.
Source code in schemacast/cast.py
Attributes¶
episodes = Field(default_factory=list)
class-attribute
instance-attribute
¶
graphs = Field(default_factory=list, description='One record graph per episode cast.')
class-attribute
instance-attribute
¶
groundings = Field(default_factory=list)
class-attribute
instance-attribute
¶
manifest
instance-attribute
¶
model_config = ConfigDict(arbitrary_types_allowed=True)
class-attribute
instance-attribute
¶
output = Field(description='The full schema and what the resolution identified.')
class-attribute
instance-attribute
¶
resolution = Field(description='The graphs resolved by their keys, without a database.')
class-attribute
instance-attribute
¶
unmapped = Field(default_factory=dict, description='By episode source id: what the text states that no type covers.')
class-attribute
instance-attribute
¶
EpisodeOutcome
¶
Bases: BaseModel
One episode's result with the intermediate steps that produced it.
Source code in schemacast/cast.py
Attributes¶
first = Field(default=None, description='The first reply, checked; None when there was none.')
class-attribute
instance-attribute
¶
graph = None
class-attribute
instance-attribute
¶
groundings = Field(default_factory=list)
class-attribute
instance-attribute
¶
model_config = ConfigDict(arbitrary_types_allowed=True)
class-attribute
instance-attribute
¶
quarantine = Field(default_factory=list, description='What the episode left out.')
class-attribute
instance-attribute
¶
result
instance-attribute
¶
selection = Field(default=None, description='The slice; None when selection failed.')
class-attribute
instance-attribute
¶
validation = Field(default=None, description='The attempt kept, after repairs.')
class-attribute
instance-attribute
¶
EpisodeResult
¶
Bases: BaseModel
What happened to one episode. Free of timing and cache facts, so a replay reproduces it byte for byte.
Source code in schemacast/cast.py
Attributes¶
failure = Field(default=None, description='Why a failed episode failed.')
class-attribute
instance-attribute
¶
fixes = Field(default_factory=list)
class-attribute
instance-attribute
¶
known = Field(default=0, description='Known entities a relation uses (refs ``k1``…).')
class-attribute
instance-attribute
¶
mentions = Field(default=0, description='Records read from the text.')
class-attribute
instance-attribute
¶
quarantined = Field(default=0, description='Items left out.')
class-attribute
instance-attribute
¶
relations = 0
class-attribute
instance-attribute
¶
repair_failure = Field(default=None, description='Why a repair request failed; the best earlier attempt is kept.')
class-attribute
instance-attribute
¶
repairs = Field(default=0, description='Typed repair rounds.')
class-attribute
instance-attribute
¶
requests = Field(default=0, description='Model requests, re-asks and repairs included.')
class-attribute
instance-attribute
¶
retrieval = None
class-attribute
instance-attribute
¶
selection = None
class-attribute
instance-attribute
¶
source_id
instance-attribute
¶
status = Field(description='``ok``: nothing left out; ``partial``: some items quarantined; ``failed``: nothing written.')
class-attribute
instance-attribute
¶
unmapped = 0
class-attribute
instance-attribute
¶
RunManifest
¶
Bases: BaseModel
How a cast was produced.
Source code in schemacast/cast.py
Attributes¶
edges = Field(description='Edges between identified vertices.')
class-attribute
instance-attribute
¶
episodes
instance-attribute
¶
graflo_version
instance-attribute
¶
max_episode_tokens
instance-attribute
¶
mentions
instance-attribute
¶
model = Field(description='Every model setting that reaches the provider.')
class-attribute
instance-attribute
¶
output_format_version = OUTPUT_FORMAT_VERSION
class-attribute
instance-attribute
¶
quarantined
instance-attribute
¶
relations
instance-attribute
¶
schema_ref
instance-attribute
¶
schemacast_version
instance-attribute
¶
slice_max_elements
instance-attribute
¶
slice_max_tokens
instance-attribute
¶
staged = Field(description='Mentions not identified without a database.')
class-attribute
instance-attribute
¶
status
instance-attribute
¶
unmapped
instance-attribute
¶
usage
instance-attribute
¶
user_instruction
instance-attribute
¶
vertices = Field(description="Vertices the batch's keys identify.")
class-attribute
instance-attribute
¶
SchemaCaster
¶
Casts episodes into one governed schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
The governed schema; every write conforms to it. |
required |
settings
|
SchemaCastSettings | None
|
Defaults to the environment. |
None
|
client
|
LLMClient | None
|
Defaults to one built from settings. |
None
|
sink
|
QuarantineSink | None
|
Where quarantined records go. Defaults to memory
(:attr: |
None
|
selection
|
SelectionConfig | None
|
Selection tuning; its budget defaults to the settings'. |
None
|
max_concurrent_episodes
|
int
|
Episodes in flight at once. |
8
|
owned
|
frozenset[str]
|
Connector-owned vertex types: linked by key, never created. |
frozenset()
|
Source code in schemacast/cast.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 | |
Attributes¶
client = client or LLMClient(self.settings.llm, LLMCache(self.settings.cache))
instance-attribute
¶
max_concurrent_episodes = max(1, max_concurrent_episodes)
instance-attribute
¶
owned = owned
instance-attribute
¶
schema = schema
instance-attribute
¶
selection = selection or SelectionConfig(max_tokens=self.settings.slice_max_tokens, max_elements=self.settings.slice_max_elements)
instance-attribute
¶
settings = settings or SchemaCastSettings()
instance-attribute
¶
sink = sink if sink is not None else MemoryQuarantineSink()
instance-attribute
¶
Methods:¶
__init__(schema, *, settings=None, client=None, sink=None, selection=None, max_concurrent_episodes=8, owned=frozenset())
¶
Source code in schemacast/cast.py
cast(episodes)
async
¶
Cast episodes; results and quarantine records keep their order.
Raises:
| Type | Description |
|---|---|
LLMConfigurationError
|
the deployment is misconfigured. |
CacheMissError
|
a miss while the cache requires hits. |
Source code in schemacast/cast.py
cast_episode(episode)
async
¶
Cast one episode and write what it left out to the sink.