Skip to content

fix(llm/frameworks): point users to LangChain when DefaultFramework has no base_url#1865

Open
Pouyanpi wants to merge 1 commit intodevelopfrom
fix/default-framework-langchain-hint
Open

fix(llm/frameworks): point users to LangChain when DefaultFramework has no base_url#1865
Pouyanpi wants to merge 1 commit intodevelopfrom
fix/default-framework-langchain-hint

Conversation

@Pouyanpi
Copy link
Copy Markdown
Collaborator

@Pouyanpi Pouyanpi commented May 7, 2026

Description

When a 0.21 config with a bare LangChain-only engine (anthropic, cohere, vertexai, deepseek, ...) lands on DefaultFramework with no env var set, _resolve_base_url raises with a hint that only points to parameters.base_url. That fix path is wrong for engines whose API is not OpenAI-compatible.

Update the error to name both fix paths:

  • parameters.base_url for OpenAI-compatible endpoints,
  • NEMOGUARDRAILS_LLM_FRAMEWORK=langchain plus the matching langchain- package for everything else.

Aligns the runtime hint with the migration guide so users hitting the error don't have to search the docs to know what the runtime is asking of them.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error messages when encountering unsupported LLM providers, now including detailed guidance on configuring OpenAI-compatible endpoints and alternative framework setup options.
  • Tests

    • Added test case to validate error message content, configuration paths, and provider information.

…as no base_url

When a 0.21 config with a bare LangChain-only engine (anthropic, cohere,
vertexai, deepseek, ...) lands on DefaultFramework with no env var set,
_resolve_base_url raises with a hint that only points to
parameters.base_url. That fix path is wrong for engines whose API is not
OpenAI-compatible.

Update the error to name both fix paths:

- parameters.base_url for OpenAI-compatible endpoints,
- NEMOGUARDRAILS_LLM_FRAMEWORK=langchain plus the matching
  langchain-<provider> package for everything else.

Aligns the runtime hint with the migration guide so users hitting the
error don't have to search the docs to know what the runtime is asking
of them.
@Pouyanpi Pouyanpi self-assigned this May 7, 2026
@Pouyanpi Pouyanpi added the bug Something isn't working label May 7, 2026
@Pouyanpi Pouyanpi added this to the v0.22.0 milestone May 7, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 7, 2026

Greptile Summary

This PR improves the user-facing error message raised by _resolve_base_url when no known base URL exists for a provider. The previous hint only pointed to parameters.base_url, which is misleading for LangChain-only engines (Anthropic, Cohere, VertexAI, etc.) that are not OpenAI-compatible.

  • default.py: The ValueError message is expanded to name both fix paths — parameters.base_url for OpenAI-compatible endpoints and NEMOGUARDRAILS_LLM_FRAMEWORK=langchain plus the matching langchain-<provider> package for everything else.
  • test_client_config.py: A focused regression test is added that exercises the "anthropic" provider path and asserts all four new message tokens are present.

Confidence Score: 5/5

Safe to merge — the only change is an improved error message string and its accompanying test.

No logic is altered; the single-line _resolve_base_url change is limited to the exception message text. The new test correctly places its excinfo.value assertions outside the with pytest.raises block (inside the enclosing try), so all four assertions will actually execute. No environment variables or network calls can influence whether the ValueError fires for "anthropic".

No files require special attention.

Important Files Changed

Filename Overview
nemoguardrails/llm/frameworks/default.py Error message in _resolve_base_url updated to include both the OpenAI-compatible fix path and the LangChain framework path; no logic changes.
tests/llm/clients/test_client_config.py New async test test_unknown_provider_error_lists_both_fix_paths verifies all four expected strings in the updated error message; assertions are correctly placed outside the with pytest.raises block.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["create_model(model_name, provider_name, kwargs)"] --> B{provider_name in\n_providers?}
    B -- Yes --> C[Call registered provider class]
    B -- No --> D{base_url in\nkwargs?}
    D -- Yes --> E[Use provided base_url]
    D -- No --> F["_resolve_base_url(provider_name)"]
    F --> G{provider_name in\n_DEFAULT_BASE_URLS?}
    G -- Yes --> H[Return known URL\nopenai / nim / ollama]
    G -- No --> I["Raise ValueError\n(UPDATED MESSAGE)\n- parameters.base_url\n- NEMOGUARDRAILS_LLM_FRAMEWORK=langchain\n- langchain-provider package"]
    E --> J[_get_or_create_client]
    H --> J
    J --> K[OpenAIChatModel]
Loading

Reviews (1): Last reviewed commit: "fix(llm/frameworks): point users to Lang..." | Re-trigger Greptile

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: d1eec270-08de-46e9-a048-d6cded4addcf

📥 Commits

Reviewing files that changed from the base of the PR and between c69efe5 and 5d76fe2.

📒 Files selected for processing (2)
  • nemoguardrails/llm/frameworks/default.py
  • tests/llm/clients/test_client_config.py

📝 Walkthrough

Walkthrough

The PR expands error messaging when a provider's default base_url is unresolved. The ValueError now includes instructions for configuring parameters.base_url for OpenAI-compatible endpoints or setting NEMOGUARDRAILS_LLM_FRAMEWORK=langchain with the corresponding langchain-<provider> package. A new test validates both guidance paths appear in the error message.

Changes

Error Message Guidance for Unknown Providers

Layer / File(s) Summary
Error Message Enhancement
nemoguardrails/llm/frameworks/default.py
ValueError message for missing provider base_url expanded to include instructions for OpenAI-compatible configuration and LangChain alternative setup.
Test Validation
tests/llm/clients/test_client_config.py
New async test asserts that the ValueError message includes both OpenAI-compatible and LangChain fix-path references for unknown providers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: improving error messaging in DefaultFramework to guide users toward LangChain as an alternative when no base_url is configured.
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 Results For Major Changes ✅ Passed Changes are minor: only error message improvement (±4 LOC). No functional logic changes. New test validates the error message format, confirming the change works as intended.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/default-framework-langchain-hint

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Collaborator

@tgasser-nv tgasser-nv left a comment

Choose a reason for hiding this comment

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

LGTM!

"Set it explicitly in model parameters: parameters.base_url"
"If your endpoint is OpenAI-compatible, set parameters.base_url. "
"Otherwise, set NEMOGUARDRAILS_LLM_FRAMEWORK=langchain and install "
"the matching langchain-<provider> package (see migration guide)."
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Could you add a link to the migration guide here (pointing to the docs)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants