Skip to content

Add LangChainAzureHook for Azure OpenAI support#70441

Open
ColtenOuO wants to merge 1 commit into
apache:mainfrom
ColtenOuO:add-langchain-azure-hook
Open

Add LangChainAzureHook for Azure OpenAI support#70441
ColtenOuO wants to merge 1 commit into
apache:mainfrom
ColtenOuO:add-langchain-azure-hook

Conversation

@ColtenOuO

Copy link
Copy Markdown
Contributor

Summary

LangChainHook's docstring already flagged this gap: "Providers with bespoke auth (AWS Bedrock, Google Vertex AI / GenAI, Azure OpenAI, Cohere, HuggingFace) reject these kwargs; per-vendor subclasses can be added later mirroring the pydantic-ai pattern." PydanticAIHook already has that pattern (PydanticAIAzureHook/PydanticAIBedrockHook/PydanticAIVertexHook, each overriding _get_provider_kwargs) -- this PR adds the first LangChain equivalent.

Without it, LangChainHook always calls init_chat_model(model, api_key=..., base_url=...), but Azure OpenAI's LangChain classes (AzureChatOpenAI, AzureOpenAIEmbeddings) don't accept base_url -- they need azure_endpoint and api_version. Verified against the real langchain-openai package: those are the actual constructor fields/aliases.

Changes

  • LangChainHook._connection_kwargs: @staticmethod -> instance method, so subclasses can override it (matches PydanticAIHook's _get_provider_kwargs). No behavior change for the base class.
  • Add LangChainAzureHook(LangChainHook), overriding _connection_kwargs to map conn.host -> azure_endpoint and read api_version from conn.extra.
  • Register the new langchain-azure connection type in provider.yaml; regenerated get_provider_info.py via breeze release-management prepare-provider-documentation --reapply-templates-only --skip-changelog --skip-readme (not hand-edited).

Test plan

  • Added 7 tests: class attributes, UI field behaviour, host -> azure_endpoint mapping, api_version from extra, embedding model uses the same mapping, empty kwargs when no credentials set.
  • Full test_langchain.py passes (28 passed).
  • ruff format/ruff check, breeze run mypy clean (mypy caught the staticmethod/instance-method override incompatibility, since fixed).
  • scripts/ci/prek/check_provider_yaml_files.py passes: LangChainAzureHook registered correctly, 0 errors.

Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 5)

@ColtenOuO

ColtenOuO commented Jul 25, 2026

Copy link
Copy Markdown
Contributor Author

Happy to add the remaining vendors (ex. Bedrock, Vertex) as follow-up PRs if that's a direction the maintainers would like to take.

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.

1 participant