Skip to content

Make common.ai tool_prefix and output_type signatures consistent - #74695

Merged
Lee-W merged 32 commits into
apache:mainfrom
astronomer:common-ai-1-0-api-unify
Nov 12, 2026
Merged

Lee-W merged 32 commits into
apache:mainfrom
astronomer:common-ai-1-0-api-unify

Conversation

@Lee-W

@Lee-W Lee-W commented Oct 14, 2026 •

Copy link
Copy Markdown
Member

Public signatures freeze at 1.0, and changing a parameter's type, default or availability afterwards is a breaking change. tool_prefix was str on some toolsets, str | None on MCPToolset and MCPHook, and missing on SQLToolset and DataFusionToolset. AgentOperator also annotated output_type narrower than LLMOperator even though both accept the same values at runtime. HookToolset keeps its deprecated tool_name_prefix alias until 2.0.

SQLToolset and DataFusionToolset also override tool_name_conflict_hint so a name conflict points users to tool_prefix. rehydrate_pydantic_output now accepts a list output_type by validating it as a union, so a list output_type no longer crashes after a HITL review.

Models returned under a list output_type are dumped through a shared dump_output_for_xcom helper. With serialize_output=True, and on task-sdk versions without the walker, the dump keeps model_dump() as in 1.0.0. A model whose class the worker cannot register is dumped with to_jsonable_python, so HttpUrl, Path and Enum fields serialize.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: [Claude] following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@Lee-W
Lee-W force-pushed the common-ai-1-0-api-unify branch from 6b90e59 to 880b666 Compare October 14, 2026 09:09
@Lee-W
Lee-W marked this pull request as ready for review October 14, 2026 09:46
Comment thread providers/common/ai/docs/changelog.rst Resolved
@Lee-W
Lee-W force-pushed the common-ai-1-0-api-unify branch 3 times, most recently from ad14ff9 to 5a39459 Compare October 14, 2026 16:29
@Lee-W
Lee-W requested a review from kaxil October 15, 2026 07:53
@Lee-W
Lee-W force-pushed the common-ai-1-0-api-unify branch 2 times, most recently from 14aa848 to 8ebf222 Compare October 19, 2026 08:36
@Lee-W
Lee-W force-pushed the common-ai-1-0-api-unify branch 3 times, most recently from fee7efb to ff71888 Compare October 21, 2026 14:59
@Lee-W
Lee-W force-pushed the common-ai-1-0-api-unify branch from ff71888 to ba54cc3 Compare October 22, 2026 10:36
@Lee-W
Lee-W requested a review from kaxil October 26, 2026 06:01
@Lee-W
Lee-W force-pushed the common-ai-1-0-api-unify branch 2 times, most recently from 51fb24c to 293be44 Compare October 27, 2026 10:13
@Lee-W
Lee-W force-pushed the common-ai-1-0-api-unify branch 3 times, most recently from b135b94 to 20cbe30 Compare October 29, 2026 04:03
Lee-W added 24 commits November 12, 2026 13:16
The worker only registers the model classes it finds in an output_type
that is a single type or a union. A model returned under
output_type=[MyModel, int] was therefore pushed to XCom as an instance
and failed to load in the downstream task with "not found in allow
list". Return it as a dict instead, as AgentOperator already did after
human review. A model under a single type or a union is still returned
as an instance.
A bare MagicMock accepts any attribute, so a call_tool signature change
would not fail these tests. Give the helper the same RunContext and
ToolsetTool specs that the other SQLToolset call_tool tests use.
…e walker

The worker walker that registers output_type classes exists only from
Airflow 3.3, so is_model_dump_required has nothing to consult on older
task-sdk versions. Defer to the caller's serialize_output there instead
of forcing a dump: the operators already pass serialize_output=True on
those versions, and rehydrate_pydantic_output returns an instance again
for a direct serialize_output=False call, as it did before.

The tests that need the walker are skipped without it, which is what the
Airflow 3.3 compatibility jobs were failing on.
- HookToolset accepts tool_name_prefix again and warns with
  AirflowProviderDeprecationWarning, as in common.ai 1.0.0
- Drop the 1.0.0 changelog note that announced the removal
…s serialize

- Models are dumped with pydantic_core.to_jsonable_python through one shared
  dump_output_for_xcom helper, so a model with an HttpUrl, Path or Enum field
  no longer fails at the XCom push
- Models inside a list, tuple, set or dict output are dumped too when the
  worker registers no class for them, such as under output_type=[list[Item], str]
- Dumped models keep field names, not aliases, as dump_output_to_json does
- serialize_output=True, and task-sdk versions without the walker, dump
  models with model_dump() as 1.0.0 did, so date, datetime, Decimal and UUID
  fields keep their types instead of turning into strings
- Only a model whose class the worker cannot register is dumped to JSON values
- An output with a set, frozenset or dict key holding a model is dumped to
  JSON values, as pydantic cannot hold a dumped model in a set or as a key
…ck does

- test_output_type.py and test_llm.py imported deserialize and serialize at
  module top, so collection failed on Airflow 2.11, 3.0 and 3.1 where
  airflow.sdk.serde does not exist
- The imports now sit in the existing try block beside the walker flag, and
  the tests that use them are already skipped without the walker
…mmon.ai docs

- With serialize_output=True every output holding a model is dumped, with
  model_dump() except where a set or dict key holds the model
- Without it only a model whose class the worker cannot register is dumped,
  so output_type=list[MyModel] still pushes instances
serialize_output=True dumped the whole output in Python mode, so a
list[Link] or dict[str, Link] kept its HttpUrl field inside a plain dict
and the XCom push failed. Dump with model_dump() only when the output is
itself a model, as 1.0.0 did, and leave a container of registered models
to serde.

A model whose class the worker cannot register is still dumped to JSON
values, wherever it sits in the output.
… docs

The serialize_output docstrings and the guide disagreed: the docstrings
said the dump uses to_jsonable_python while the guide said model_dump().
Both are right for different outputs, so state the three cases in each
place: a model that is itself the output with serialize_output=True is
dumped to Python values, a container of registered models is left to
serde, and a model the worker cannot register is dumped to JSON values.

AgentOperator walks list, tuple and dict values only, while the LLM
operators also walk sets and dict keys, so stop saying the Agent row
follows the same rules as @task.llm.
AgentOperator dumped models with its own helper while LLMOperator,
@task.llm and LLMFileAnalysisOperator used dump_output_for_xcom, so one
output_type produced different XCom values: a model with
serialize_by_alias came out as fullName from the agent but full_name from
the LLM operators, and a date next to a model in a tuple stayed a date.

AgentOperator now calls dump_output_for_xcom as well. Tuples next to an
unregistered model arrive as lists, and on task-sdk before 3.3 a top-level
model is dumped while list[MyModel] is pushed as instances, as in 1.0.0.
… walker

The Compat 3.1.8 and 3.2.2 jobs failed
test_execute_with_hitl_returns_the_approved_output_as_output_type[list-in-output-marker]:
it expects a dict but gets the model instance. Those task-sdk versions ship
airflow.sdk.serde without the deserialization walker, so the operator
deliberately pushes nested models as instances (a top-level model is still
model_dump()ed). The enum-and-url-fields case in the same parametrize already
carries requires_typed_xcom; add the same mark here.
Four toolsets and the hook each carried their own copy of the prefix handling, so they could drift apart.
Both now take the prefix validation, tool naming and id suffix from the shared helper, so a fix to prefix handling lands in one place.
…oxToolset

Both now take the prefix validation, tool naming and id suffix from the shared helper, so a fix to prefix handling lands in one place.
HookToolset used a fourth copy of the identifier check; it now calls the shared one.
…lker

Without iter_pydantic_models (Airflow < 3.3 or an older task-sdk) the worker
registers no class, so is_model_dump_required now treats every model in the
output as unregistered instead of returning False. A list of models is pushed
as dicts there, as AgentOperator already did in 1.1.0, and the LLM operators
follow it.
…anges

1.1.0 is released, so its changelog note and the upgrade list in
structured_output.rst are back to the text in the tag. The changes made after
it, the dump of models in containers without the walker and the MCP
tool_prefix signature, get their own notes above 1.1.0 and a short section in
structured_output.rst. stability.rst no longer says list[MyModel] is pushed as
instances before Airflow 3.3.
The serialize_by_alias, tuple and date changes of AgentOperator apply whenever a
model in the output is dumped, also on Airflow < 3.3. The new section in
structured_output.rst sat in the middle of the page and turned the paragraphs
after it into its own subsection, so it now closes the page.
… walker

- Skip the output_type tests that assume the 3.3 walker when it is absent
- Test that every model, a top-level one included, is dumped to a dict without the walker
- State in the changelog and structured_output docs that LLMOperator, @task.llm and
  LLMFileAnalysisOperator push a top-level model as a dict on Airflow < 3.3
…Mixin

- Drop _strip_tool_prefix; SQLToolset, DataFusionToolset and ObjectStorageToolset
  use _find_base_tool_name, so with a tool_prefix set an unprefixed name raises
  "Unknown tool", as SandboxToolset already did
- Move tool_name_conflict_hint into ToolPrefixMixin, so ObjectStorageToolset and
  SandboxToolset get it too
…dration

- rehydrate_pydantic_output returns the raw text on a TypeError only when a list
  of output types cannot be joined into a union; a TypeError raised while
  building the TypeAdapter now propagates
- Make is_model_dump_required private, as only output_type.py calls it
…i's OutputSpec

- output_type accepts OutputSpec[Any] | UnionType, so output markers such as
  ToolOutput and NativeOutput and output functions type-check, as documented
- Mention the output markers and output functions in the output_type docstrings
- Add a "When a model arrives as a dict" section to structured_output.rst and
  drop the section that repeated its rules
- Point the serialize_output docstrings, stability.rst, the operator pages and
  the unreleased changelog note at that section instead of repeating the rules
- Correct the claim that a top-level model is dumped to JSON values on
  Airflow < 3.3; it is dumped with model_dump(), as in 1.1.0
- Stop naming the internal output helper in user-facing docs
@Lee-W
Lee-W force-pushed the common-ai-1-0-api-unify branch from f74af9b to 654306c Compare November 12, 2026 05:16
@Lee-W
Lee-W merged commit 2448be4 into apache:main Nov 12, 2026
79 checks passed
@Lee-W
Lee-W deleted the common-ai-1-0-api-unify branch November 12, 2026 05:59
@shahar1 shahar1 mentioned this pull request Nov 18, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants