lpgcast.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 → resolve identities and assemble. 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 = 2
module-attribute
¶
Classes¶
CastResult
¶
Bases: BaseModel
The output of a cast.
Source code in lpgcast/cast.py
Attributes¶
episodes = Field(default_factory=list)
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 every episode's graph.")
class-attribute
instance-attribute
¶
pending = Field(default_factory=list)
class-attribute
instance-attribute
¶
EpisodeOutcome
¶
Bases: BaseModel
One episode's result with the intermediate steps that produced it.
Source code in lpgcast/cast.py
Attributes¶
first = Field(default=None, description='The first reply, checked; None when there was none.')
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
¶
resolution = None
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 lpgcast/cast.py
Attributes¶
edges = 0
class-attribute
instance-attribute
¶
failure = Field(default=None, description='Why a failed episode failed.')
class-attribute
instance-attribute
¶
fixes = Field(default_factory=list)
class-attribute
instance-attribute
¶
pending = Field(default=0, description='Edges awaiting a secondary-identity lookup.')
class-attribute
instance-attribute
¶
quarantined = 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
¶
vertices = 0
class-attribute
instance-attribute
¶
LPGCaster
¶
Casts episodes into one governed schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
Schema
|
The governed schema; every write conforms to it. |
required |
settings
|
LPGCastSettings | 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
|
Source code in lpgcast/cast.py
196 197 198 199 200 201 202 203 204 205 206 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 | |
Attributes¶
client = client or LLMClient(self.settings.llm, LLMCache(self.settings.cache))
instance-attribute
¶
max_concurrent_episodes = max(1, max_concurrent_episodes)
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 LPGCastSettings()
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)
¶
Source code in lpgcast/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 lpgcast/cast.py
cast_episode(episode)
async
¶
Cast one episode and write what it left out to the sink.
RunManifest
¶
Bases: BaseModel
How a cast was produced.