Skip to content

feat(models): add Azure AI Foundry to unified model provider setup#13924

Closed
pareek-ml wants to merge 2 commits into
langflow-ai:release-1.11.0from
pareek-ml:feat/azure-ai-foundry-provider
Closed

feat(models): add Azure AI Foundry to unified model provider setup#13924
pareek-ml wants to merge 2 commits into
langflow-ai:release-1.11.0from
pareek-ml:feat/azure-ai-foundry-provider

Conversation

@pareek-ml

@pareek-ml pareek-ml commented Jun 30, 2026

Copy link
Copy Markdown

What & why

Adds Azure AI Foundry as a first-class model provider in Langflow's unified model system (Settings → Model Providers), enabling centralized configuration of endpoint and API key — identical to how OpenAI, Anthropic, and Ollama work today.

Supersedes #13912 by @HimavarshaVS with two fixes applied:

  • Docstring coverage: all 12 test functions now have docstrings (fixes CodeRabbit's 0% docstring-coverage warning)
  • Credential validation coverage: three early-return paths (missing model_name, missing api_key, missing endpoint) are now tested (fixes Codecov's credentials.py partial-coverage report)

How

Layer Change
azure_ai_foundry_constants.py Seed model catalog: gpt-4o, gpt-4o-mini, gpt-4.1, o3-mini, Mistral-Large-3 with capability flags
model_metadata.py "Azure AI Foundry" entry: AZURE_AI_FOUNDRY_API_KEY (credential) + AZURE_AI_FOUNDRY_ENDPOINT (endpoint), AzureAIOpenAIApiChatModel mapping
class_registry.py Lazy import for AzureAIOpenAIApiChatModel from langchain-azure-ai
provider_queries.py Import + add seed catalog to _STATIC_MODELS_DETAILED
credentials.py Validation branch: constructs model with max_tokens=1, invokes test call; early-returns when any required field is absent
instantiation.py get_llm branch: resolves AZURE_AI_FOUNDRY_ENDPOINT from provider vars or env; raises ValueError with actionable message when missing
settings/constants.py Both env vars added to VARIABLES_TO_GET_FROM_ENVIRONMENT
flow_requirements.py "Azure AI Foundry": {"langchain-azure-ai"}

Tests

12 tests in test_azure_ai_foundry_provider.py covering:

  • Registry presence and metadata shape
  • Parameter mapping resolution
  • Env var registration and requirements generation
  • Credential validation: success + all 3 early-return paths
  • get_llm: endpoint + credential wiring and missing-endpoint ValueError

Test plan

  • Configure Azure AI Foundry in Settings → Model Providers with API key + endpoint from the Foundry portal
  • Enable a deployment matching a model in the catalog (e.g. gpt-4o)
  • Run a Language Model or Agent flow and confirm inference succeeds

Refs #13912

Summary by CodeRabbit

  • New Features

    • Added support for Azure AI Foundry as a model provider.
    • Included several Foundry models in the available model catalog, including a default option.
    • Added automatic requirement detection for the provider’s client package.
  • Bug Fixes

    • Improved credential and endpoint handling so validation and setup fail gracefully when required settings are missing.
    • Ensured model connection details are applied consistently during setup and usage.
  • Tests

    • Added coverage for provider registration, model mapping, requirements, validation, and connection setup.

Adds Azure AI Foundry as a first-class model provider in Langflow's
unified model system, enabling centralized configuration via
Settings → Model Providers.

- Register "Azure AI Foundry" in MODEL_PROVIDER_METADATA with
  AZURE_AI_FOUNDRY_API_KEY (required, secret, langchain_param=credential)
  and AZURE_AI_FOUNDRY_ENDPOINT (required, non-secret, langchain_param=endpoint)
- Add AzureAIOpenAIApiChatModel to the lazy-import class registry
  (langchain-azure-ai package, with install hint)
- Add seed model catalog (gpt-4o, gpt-4o-mini, gpt-4.1, o3-mini,
  Mistral-Large-3) with capability flags to _STATIC_MODELS_DETAILED
- Extend validate_model_provider_key with an Azure AI Foundry branch
  that constructs AzureAIOpenAIApiChatModel and invokes a test call;
  returns early when api_key, endpoint, or model_name is absent
- Extend get_llm with an Azure AI Foundry branch that resolves
  AZURE_AI_FOUNDRY_ENDPOINT from provider vars or env and raises
  ValueError with an actionable message when missing
- Register both env vars in VARIABLES_TO_GET_FROM_ENVIRONMENT for
  automatic environment import
- Add langchain-azure-ai to flow requirements map so flows using
  this provider include the package in generated requirements.txt

Tests (12 total, full coverage of new paths):
- Provider registry presence and metadata shape
- Parameter mapping resolution (model_class, api_key_param)
- Env var registration and requirements generation
- Credential validation: success path and all three early-return
  paths (missing model, missing api_key, missing endpoint)
- get_llm: endpoint + credential wiring and missing-endpoint error

Supersedes langflow-ai#13912 with docstrings on all test functions (fixing
CodeRabbit's docstring-coverage warning) and tests for the three
credential validation early-return paths (fixing Codecov's
credentials.py partial-coverage report).
@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 194a37f8-7e03-48dd-96dc-f35d51d91f77

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR adds Azure AI Foundry as a unified model provider in lfx. It introduces model catalog metadata, provider configuration, a lazy-import class registry entry, credential validation logic, LLM instantiation wiring (endpoint resolution with gated env fallback), requirement-package fallback mapping, environment variable registration, and accompanying unit tests.

Changes

Azure AI Foundry provider integration

Layer / File(s) Summary
Provider and model metadata definitions
src/lfx/src/lfx/base/models/azure_ai_foundry_constants.py, src/lfx/src/lfx/base/models/model_metadata.py, src/lfx/src/lfx/base/models/unified_models/class_registry.py, src/lfx/src/lfx/base/models/unified_models/provider_queries.py, src/lfx/src/lfx/services/settings/constants.py
Adds a seed model catalog (gpt-4o, gpt-4o-mini, gpt-4.1, o3-mini, Mistral-Large-3), registers "Azure AI Foundry" in MODEL_PROVIDER_METADATA with API key/endpoint variables and AzureAIOpenAIApiChatModel mapping, adds a lazy-import class registry entry, wires the model catalog into the static provider query list, and registers the two env var names for auto-import.
Credential validation for Azure AI Foundry
src/lfx/src/lfx/base/models/unified_models/credentials.py
Adds "Azure AI Foundry" to providers requiring validation_model and implements a validation branch that constructs AzureAIOpenAIApiChatModel and invokes it as a test call, returning early when required values are missing.
LLM instantiation and env fallback gating
src/lfx/src/lfx/base/models/unified_models/instantiation.py
Adds a gated environment fallback helper used for WatsonX and Ollama URL resolution, adds an Azure AI Foundry endpoint-resolution branch in get_llm that raises ValueError if missing, adds a helper to apply registered provider connection metadata, and simplifies embeddings model_kwargs normalization.
Dependency requirement inference
src/lfx/src/lfx/utils/flow_requirements.py
Maps "Azure AI Foundry" to the langchain-azure-ai package in the fallback requirement mapping.
Unit tests for Azure AI Foundry provider
src/lfx/tests/unit/base/models/test_azure_ai_foundry_provider.py
Adds tests for provider registry/metadata shape, param mapping resolution, env var registration, requirement generation, credential validation success and early-return paths, and get_llm wiring including missing-endpoint error handling.

Sequence Diagram(s)

sequenceDiagram
  participant Flow
  participant get_llm
  participant _env_if_allowed
  participant AzureAIOpenAIApiChatModel

  Flow->>get_llm: request LLM("Azure AI Foundry", model_name)
  get_llm->>get_llm: resolve AZURE_AI_FOUNDRY_ENDPOINT (component/db)
  get_llm->>_env_if_allowed: check env fallback if not found
  _env_if_allowed-->>get_llm: endpoint value or None
  alt endpoint missing
    get_llm-->>Flow: raise ValueError("Azure AI Foundry endpoint is required")
  else endpoint resolved
    get_llm->>AzureAIOpenAIApiChatModel: construct(credential, endpoint, model)
    AzureAIOpenAIApiChatModel-->>get_llm: chat model instance
    get_llm-->>Flow: return LLM instance
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

  • langflow-ai/langflow#13185: Both PRs extend the unified model provider system in the same core modules to add a new provider branch (OpenRouter vs. Azure AI Foundry).
  • langflow-ai/langflow#13684: Both PRs modify LLM instantiation wiring in instantiation.py, touching provider-specific connection parameter resolution.

Suggested labels

enhancement

Suggested reviewers

  • ogabrielluiz
  • Cristhianzl
🚥 Pre-merge checks | ✅ 8 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (8 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding Azure AI Foundry to the unified model provider setup.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Test Coverage For New Implementations ✅ Passed New backend test_*.py file covers Azure AI Foundry registry, metadata, requirements, validation, and get_llm wiring; tests are concrete, not placeholders.
Test Quality And Coverage ✅ Passed Tests cover provider metadata, requirements, validation success/early returns, and get_llm wiring/error with pytest-style assertions; no async/API gaps apply.
Test File Naming And Structure ✅ Passed New backend test module uses test_*.py, groups pytest tests with descriptive names, and covers positive/negative paths plus edge cases.
Excessive Mock Usage Warning ✅ Passed Mocking is limited and appropriate: 3/12 tests use patching to isolate external imports and get_llm boundaries, while most tests hit real metadata/requirements logic.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 30, 2026
@pareek-ml

Copy link
Copy Markdown
Author

Closing in favour of the cleaner bundle approach.

After looking at how #13916 works, this PR is doing exactly what #13916 was built to prevent — touching model_metadata.py, class_registry.py, credentials.py, instantiation.py, provider_queries.py, settings/constants.py, and flow_requirements.py directly.

Most of those core edits are already handled generically by the registry:

  • Endpoint wiring → _apply_registered_provider_connection via langchain_param: "endpoint"
  • Credential validation → validator: dotted-path callable
  • Class lazy-import → model_class: in ProviderSpec

The one genuine gap is _STATIC_MODELS_DETAILEDProviderSpec has no models[] field, so a bundle can't seed a static catalog (gpt-4o, gpt-4o-mini, etc.) without a core edit to provider_queries.py.

The right fix is a small extension to ProviderSpec in provider_registry.py:

models: list[dict] = field(default_factory=list)

…and a corresponding append to _STATIC_MODELS_DETAILED inside register_provider. Once that lands, lfx-azure-ai-foundry can be a zero-core-edit bundle just like lfx-vllm.

I'll open a PR against feat/model-provider-bundles that adds models[] to ProviderSpec + ships the Azure AI Foundry bundle on top of it. That way #13912 / this PR don't create double work for maintainers.

cc @erichare

@pareek-ml pareek-ml closed this Jun 30, 2026
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Jun 30, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/lfx/tests/unit/base/models/test_azure_ai_foundry_provider.py (1)

150-169: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Early-return tests don't guard against a real network call on regression.

Unlike the success test, these tests don't mock langchain_azure_ai/AzureAIOpenAIApiChatModel, yet model_name="gpt-4o" is supplied. If the early-return guard in credentials.py ever regresses, these tests would attempt a real import/network call to Azure instead of failing with a clear assertion — making CI flaky/slow instead of deterministically red.

🧪 Suggested fix: mock the model and assert it wasn't called
 def test_validate_model_provider_key_azure_ai_foundry_returns_early_without_api_key():
     """validate_model_provider_key must return without error when API key is absent."""
     from lfx.base.models.unified_models import validate_model_provider_key
 
-    validate_model_provider_key(
-        "Azure AI Foundry",
-        {"AZURE_AI_FOUNDRY_ENDPOINT": "https://example.services.ai.azure.com/openai/v1"},
-        model_name="gpt-4o",
-    )
+    calls = []
+
+    class FakeFoundryChatModel:
+        def __init__(self, **kwargs):
+            calls.append(kwargs)
+
+    fake_chat_models = SimpleNamespace(AzureAIOpenAIApiChatModel=FakeFoundryChatModel)
+    with patch.dict(
+        "sys.modules",
+        {"langchain_azure_ai.chat_models": fake_chat_models},
+    ):
+        validate_model_provider_key(
+            "Azure AI Foundry",
+            {"AZURE_AI_FOUNDRY_ENDPOINT": "https://example.services.ai.azure.com/openai/v1"},
+            model_name="gpt-4o",
+        )
+    assert calls == []

Same applies to test_validate_model_provider_key_azure_ai_foundry_returns_early_without_endpoint (Lines 161-169).

As per coding guidelines, "verify the tests actually cover the new or changed behavior rather than acting as placeholders."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/lfx/tests/unit/base/models/test_azure_ai_foundry_provider.py` around
lines 150 - 169, The Azure AI Foundry early-return tests in
test_validate_model_provider_key_azure_ai_foundry_returns_early_without_api_key
and
test_validate_model_provider_key_azure_ai_foundry_returns_early_without_endpoint
should also mock the underlying langchain_azure_ai / AzureAIOpenAIApiChatModel
path so they fail deterministically if the guard in validate_model_provider_key
(from unified_models/credentials logic) regresses. Update both tests to patch
the model import/construction and assert it is not called when either the API
key or endpoint is missing, instead of relying only on the absence of an
exception.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/lfx/tests/unit/base/models/test_azure_ai_foundry_provider.py`:
- Around line 150-169: The Azure AI Foundry early-return tests in
test_validate_model_provider_key_azure_ai_foundry_returns_early_without_api_key
and
test_validate_model_provider_key_azure_ai_foundry_returns_early_without_endpoint
should also mock the underlying langchain_azure_ai / AzureAIOpenAIApiChatModel
path so they fail deterministically if the guard in validate_model_provider_key
(from unified_models/credentials logic) regresses. Update both tests to patch
the model import/construction and assert it is not called when either the API
key or endpoint is missing, instead of relying only on the absence of an
exception.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 3ef7e3ed-bcca-474e-bfbc-bfd3cb20aba4

📥 Commits

Reviewing files that changed from the base of the PR and between c7d7676 and e85acf9.

📒 Files selected for processing (9)
  • src/lfx/src/lfx/base/models/azure_ai_foundry_constants.py
  • src/lfx/src/lfx/base/models/model_metadata.py
  • src/lfx/src/lfx/base/models/unified_models/class_registry.py
  • src/lfx/src/lfx/base/models/unified_models/credentials.py
  • src/lfx/src/lfx/base/models/unified_models/instantiation.py
  • src/lfx/src/lfx/base/models/unified_models/provider_queries.py
  • src/lfx/src/lfx/services/settings/constants.py
  • src/lfx/src/lfx/utils/flow_requirements.py
  • src/lfx/tests/unit/base/models/test_azure_ai_foundry_provider.py

pareek-ml added a commit to pareek-ml/langflow that referenced this pull request Jul 3, 2026
…ai-foundry bundle

Part 1 — registry extension (provider_registry.py, manifest.py, loader):
Adds a `models: list[dict]` field to ProviderSpec so a bundle can seed a
static model catalog without editing core files. register_provider() appends
the list to _STATIC_MODELS_DETAILED in-place; clear() reverses it. The
extension.json schema gains a matching `models[]` array; the loader passes it
through to ProviderSpec. Zero behavior change when no bundle is loaded.

Part 2 — lfx-azure-ai-foundry bundle (src/bundles/azure-ai-foundry/):
Ships Azure AI Foundry as a provider-only Extension Bundle with zero core
edits, superseding the core-edit approach in langflow-ai#13912 and langflow-ai#13924.
- extension.json: declares provider metadata (AZURE_AI_FOUNDRY_API_KEY +
  AZURE_AI_FOUNDRY_ENDPOINT), AzureAIOpenAIApiChatModel lazy import, dotted-
  path validator, and a seed catalog (gpt-4o, gpt-4o-mini, gpt-4.1, o3-mini,
  Mistral-Large-3) via the new models[] field.
- validator.py: constructs AzureAIOpenAIApiChatModel and calls invoke(); early-
  returns when api_key, endpoint, or model_name is absent.

Tests (10):
- models[] injection into _STATIC_MODELS_DETAILED and clear() reversal.
- End-to-end load through the real extension loader: provider appears in
  get_model_providers() and seed models in get_models_detailed().
- Validator: early-return paths (missing model, key, endpoint), success, and
  ValueError on invoke() failure.

Refs langflow-ai#13912, closes langflow-ai#13924
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant