Skip to content

PydanticAI hooks use wrong connection_type convention which breaks with dynamic lookup #72316

Description

@dabla

Under which category would you file this issue?

Providers

Apache Airflow version

Not version-specific — reproducible on any version shipping apache-airflow-providers-common-ai with PydanticAIAzureHook, PydanticAIBedrockHook, or PydanticAIVertexHook.

What happened and how to reproduce it?

Connection.get_hook() raises AirflowException: Unknown hook type "pydanticai_azure" (or
pydanticai_bedrock / pydanticai_vertex) whenever the connection is stored as a URI in a
secrets backend such as HashiCorp Vault or AWS Secrets Manager.

Stack trace:

AirflowException: Unknown hook type "pydanticai_azure"
  File ".../airflow/sdk/execution_time/task_runner.py", line 1579 in _run_task_and_map_outcome
  File ".../airflow/sdk/definitions/connection.py", line 223 in get_hook

How to reproduce:

  1. Store a connection whose type is pydanticai-azure as a URI in a secrets backend
    (e.g. pydanticai-azure://<host>?... in HashiCorp Vault).
  2. Reference that connection from a Dag using @task.agent / AgentOperator.
  3. The task fails with Unknown hook type "pydanticai_azure".

The bug does not reproduce when the connection is stored in the metadata DB directly, because
in that case conn_type is stored as a plain field and never passes through URI normalization.

Root cause:

Connection.get_uri() serializes conn_type with hyphens to produce a valid URI scheme:

uri = f"{self.conn_type.lower().replace('_', '-')}://"

Connection._normalize_conn_type() is the intended reverse — it converts hyphens back to
underscores when a URI is parsed:

elif "-" in conn_type:
    conn_type = conn_type.replace("-", "_")

This round-trip works correctly for every other multi-word hook in the codebase because they all
declare their conn_type with underscores:

Hook conn_type URI scheme
Azure Data Factory azure_data_factory azure-data-factory://
Google Cloud Platform google_cloud_platform google-cloud-platform://
Hive CLI hive_cli hive-cli://
Spark Connect spark_connect spark-connect://

The three pydantic-ai hooks are the only outliers in the entire provider tree — they declare
their conn_type with hyphens in both provider.yaml and the hook class:

# providers/common/ai/hooks/pydantic_ai.py
class PydanticAIAzureHook(...):
    conn_type = "pydanticai-azure"   # ← hyphen; all other multi-word hooks use underscore

class PydanticAIBedrockHook(...):
    conn_type = "pydanticai-bedrock"

class PydanticAIVertexHook(...):
    conn_type = "pydanticai-vertex"
# providers/common/ai/provider.yaml
connection-type: pydanticai-azure
connection-type: pydanticai-bedrock
connection-type: pydanticai-vertex

So the broken round-trip is:

URI from secrets backend : "pydanticai-azure://..."
  → _normalize_conn_type() → "pydanticai_azure"   (underscore form)
  → hooks.get("pydanticai_azure") → None           (hook is registered under "pydanticai-azure")
  → AirflowException: Unknown hook type "pydanticai_azure"

What you think should happen instead?

The three hook conn_type attributes and the corresponding provider.yaml connection-type
entries should be renamed to use underscores, consistent with every other multi-word provider:

Current Proposed
pydanticai-azure pydanticai_azure
pydanticai-bedrock pydanticai_bedrock
pydanticai-vertex pydanticai_vertex

default_conn_name values already use underscores (pydanticai_azure_default) so those are
unaffected.

Since these providers are relatively new, migration impact should be limited. A
_normalize_conn_type alias (like the existing postgresqlpostgres entry) could be added
as a compatibility shim for users who already have connections stored with the hyphenated type.

Operating System

Redhat 44

Deployment

Official Apache Airflow Helm Chart

Apache Airflow Provider(s)

common-ai

Versions of Apache Airflow Providers

All versions shipping PydanticAIAzureHook, PydanticAIBedrockHook, or PydanticAIVertexHook.

Official Helm Chart version

1.22.0 (latest released)

Kubernetes Version

No response

Helm Chart configuration

No response

Docker Image customizations

No response

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions