airflow.providers.common.ai.batch.output_schema¶
Provider-neutral structured-output layer for @task.llm_batch.
This module knows nothing about any provider – it only knows Pydantic. It
turns output_type into a JSON Schema adapters can translate into their own
request shape (OutputSpec), and turns an adapter’s extracted
response back into a validated value or an explicit failure
(ValidationOutcome).
Deliberately does not call
rehydrate_pydantic_output():
that helper’s failure mode is “validation failed -> return the raw string
unchanged”, which is correct for the HITL round-trip it was built for but
wrong here – a batch item that fails validation must be recorded as failed
(status: "invalid_output"), never silently downgraded into a
string that merely looks like a success.
Classes¶
The translation of |
|
The result of validating one item's |
Functions¶
|
Build the |
|
Validate one item's extracted output against |
Module Contents¶
- class airflow.providers.common.ai.batch.output_schema.OutputSpec[source]¶
The translation of
output_typeinto a provider-agnostic structured-output request.Built once per task execution (the schema is identical for every request in the batch), then passed to the adapter’s
build_output_directive()and, on the way back, tovalidate_extracted_output().
- airflow.providers.common.ai.batch.output_schema.build_output_spec(output_type)[source]¶
Build the
OutputSpecfor a@task.llm_batchoutput_type.output_type is str(the default) produces an unstructured spec: no schema is generated and adapters skipbuild_output_directive/extract_outputvalidation entirely. Any other type – aBaseModelsubclass, or another typeTypeAdaptersupports (int,list[str], …), matching what@task.llm’soutput_typealready accepts – produces a JSON Schema.- Raises:
LLMBatchOutputTypeError –
output_typecannot produce a JSON Schema at all (e.g. a bare class with no Pydantic-compatible fields). Raised eagerly, before any request is built or submitted.
- class airflow.providers.common.ai.batch.output_schema.ValidationOutcome[source]¶
The result of validating one item’s
ExtractedOutputagainst anOutputSpec.
- airflow.providers.common.ai.batch.output_schema.validate_extracted_output(extracted, spec)[source]¶
Validate one item’s extracted output against
spec, never raising.“The model returned something that doesn’t match
output_type” is batch data, not an exception – the caller recordsok=Falseitems asstatus: "invalid_output"and keeps processing the rest of the stream.When
spec.is_structuredisFalse(output_type is str), the text passes through unchanged with no validation at all.