Skip to content

common-ai: let a generic pydanticai connection set a default model provider - #75909

Merged
kaxil merged 3 commits into
apache:mainfrom
jlaneve:common-ai-default-provider
Oct 28, 2026
Merged

kaxil merged 3 commits into
apache:mainfrom
jlaneve:common-ai-default-provider

Conversation

@jlaneve

@jlaneve jlaneve commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

a generic pydanticai connection had no platform of its own, so a bare model_id failed with "Connection '...' has no default model provider, so the bare model name '...' cannot be resolved". a connection pointed at an OpenAI-compatible gateway made every DAG author pick the right pydantic-ai prefix, and openai: (Responses API) vs openai-chat: (Chat Completions) is easy to get wrong

an optional model_provider key in the extra (shown in the form as Default Model Provider, named after the hook's model_provider attribute so it does not read as an Airflow provider package) now qualifies bare ids on a generic connection:

{"model_provider": "openai-chat"}

with that set, @task.llm(llm_conn_id="my_gateway", model_id="claude-sonnet-4-5") resolves to openai-chat:claude-sonnet-4-5

  • the value is checked with the same infer_provider_class lookup the prefix check uses, so a typo raises when the model is resolved, even if the model id carries its own prefix
  • ids that already carry a recognized prefix are used as is, and connections without the key behave as before
  • vendor types (Azure/Bedrock/Vertex) keep their class-level model_provider and ignore the key, since their credential fields only fit their own platform
  • fallback chains use it too: a bare name forwarded to a generic fallback is qualified with that fallback's model_provider, and the colon-bearing-id gate compares it like a class attribute
  • @task.llm_batch applies it the same way, to model_id, the Model field and a request's model, and openai-chat: selects the OpenAI batch adapter, which already submits to Chat Completions
  • The typo warning for an unrecognized prefix: now fires only on vendor types, because behind a gateway llama3:70b is the normal spelling
  PydanticAIHook.get_conn()                hooks/pydantic_ai.py
  ├─ _resolve_own_model()
+ │  ├─ _get_model_provider()             # class attr, else extra["model_provider"]
  │  └─ _qualify_model_name()
- │     └─ self.model_provider
+ │     └─ _get_model_provider()
  └─ _resolve_fallback_models()
+    ├─ _get_model_provider()             # once, before the loop
-    └─ _resolve_own_model(forwarded_model_provider=self.model_provider)
+    └─ _resolve_own_model(forwarded_model_provider=<that value>)

docs: the pydanticai connection page documents Default Model Provider and adds an OpenAI-compatible gateway example, and the troubleshooting, model providers, fallback and self-hosted pages no longer say a bare name always fails. The @task.llm_batch page covers Default Model Provider and openai-chat: through a gateway. provider.yaml gets the matching conn-field

closes: #75906


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

Generated-by: Claude Code (Claude Opus 5.5) 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.

The generic pydanticai connection has no platform of its own, so every
model id on it needs a pydantic-ai prefix such as "openai-chat:". A
connection pointed at an OpenAI-compatible gateway then makes every DAG
author pick the prefix the gateway speaks.

An optional "provider" key in the connection extra (shown as Default
Provider in the form) now qualifies bare model ids on that connection,
including when they are forwarded down a fallback chain. The value is
checked with infer_provider_class, so an unknown provider fails when the
model is resolved. Vendor connection types keep their own platform and
ignore the key. Prefixed ids and connections without the key behave as
before.

closes: apache#75906
@kaxil

kaxil commented Oct 28, 2026

Copy link
Copy Markdown
Member

Just posted comments so I don't forget, but I'll tackle them

…ame:tag ids

@task.llm_batch read the same Model field but passed it to dispatch unqualified,
so a bare name on a Default Provider connection failed, and `openai-chat:` had no
batch adapter. The batch operator now qualifies the batch-level and per-request
model the way PydanticAIHook does, and `openai-chat` selects the OpenAI adapter,
which already submits to Chat Completions.

The typo warning for an unrecognized `prefix:` now fires only on vendor types:
behind a generic connection's Default Provider, `llama3:70b` is the normal
spelling. Docs scope the resolution rule to sources 1-3, note how to send a
`mistral:7b`-style tag through a gateway, and list `openai-chat:` for vLLM.
…vider

The form label and the extra key both said "provider", which in an Airflow
connection form reads as an Airflow provider package. The label is now
"Default Model Provider" and the key is `model_provider`, matching the hook's
own `model_provider` attribute and its "no default model provider" errors.
Nothing has shipped with the old key, so there is nothing to deprecate.
@kaxil
kaxil enabled auto-merge (squash) October 28, 2026 21:19
@kaxil
kaxil merged commit 2c560aa into apache:main Oct 28, 2026
78 of 79 checks passed
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.

common-ai: let a generic pydanticai connection set a default model provider

2 participants