Skip to content

fix(ui): render dict-shaped fallback entries in router settings - #26515

Closed
jayy-77 wants to merge 8 commits into
BerriAI:litellm_oss_branchfrom
jayy-77:fix/router-settings-ui-dict-fallbacks
Closed

jayy-77 wants to merge 8 commits into
BerriAI:litellm_oss_branchfrom
jayy-77:fix/router-settings-ui-dict-fallbacks

Conversation

@jayy-77

@jayy-77 jayy-77 commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #26473

Pre-Submission checklist

  • Tests added — 5 new regression cases in ui/litellm-dashboard/src/components/Settings/RouterSettings/Fallbacks/Fallbacks.test.tsx. UI-only change, so tests/test_litellm/ does not apply here.
  • UI build passes (npm run build ✅), vitest passes (47/47 in RouterSettings/**, 20/20 in Fallbacks.test.tsx).
  • make test-unit not impacted — no Python files touched.
  • Scope isolated — only fixes the router-settings dict-fallback render crash.
  • Greptile review — will request @greptileai after the PR is open.

Type

🐛 Bug Fix

Changes

Problem

router_settings.fallbacks accepts dict-shaped chain entries at runtime, e.g.

router_settings:
  fallbacks:
    - primary-model:
        - model: fallback-model
          api_key: "..."
          extra_headers: {}

This shape is used to override request-level params (notably api_key / Authorization) on the fallback attempt — important when the primary model uses request-injected auth that must not carry over to the fallback. Runtime support lives in litellm/router_utils/fallback_event_handlers.py:122-132 (kwargs.update(mg) for dict items) and _check_non_standard_fallback_format.

The Admin UI's Fallbacks.tsx typed each chain entry as string and rendered it directly as a React child, so any dict entry crashed the router-settings page:

Uncaught Error: Objects are not valid as a React child (found: object with keys {model, api_key, extra_headers}).

(React error #31 — exactly what the issue reports.)

Fix (UI-only)

ui/litellm-dashboard/src/components/Settings/RouterSettings/Fallbacks/Fallbacks.tsx:

  • Widened the chain-item type to FallbackChainItem = string | { model?: string; [key: string]: any }.
  • Added getFallbackChainItemDisplayName() to resolve the visible label from string, dict.model, or stringified JSON.
  • ChainCard now tags dict entries with an override badge and shows the override JSON in a tooltip on hover.
  • api_key, authorization, token, secret, password (and matching keys inside extra_headers) are masked with •••••• so secrets never enter the DOM.
  • React keys made index-stable (\${i}-\${displayName}) since the same model can repeat across overrides.

The existing add/delete flows already preserved unrelated entries unchanged, so dict items round-trip safely with no backend changes. UpdateRouterConfig.fallbacks: Optional[List[dict]] already permits the dict shape on /config/update.

Tests

ui/litellm-dashboard/src/components/Settings/RouterSettings/Fallbacks/Fallbacks.test.tsx adds 5 cases under dict-shaped fallback chain entries:

  1. renders without crashing when a fallback chain entry is a dict — locks in the React error updating version #31 fix.
  2. marks dict fallback entries with an override tag — visual signal that the entry has overrides.
  3. renders mixed string and dict entries in the same chain — exactly one override tag for the dict, none for the string.
  4. preserves dict fallbacks when deleting a sibling fallback row — round-trip safety: the dict entry is unchanged after a setCallbacksCall triggered by deleting another row.
  5. does not leak api_key into the rendered DOM — masking guarantee.

Suite results:

  • Fallbacks.test.tsx: 20/20 ✅ (15 pre-existing + 5 new)
  • RouterSettings/**: 47/47 ✅
  • npm run build: ✅
  • tsc --noEmit (filtered to touched files): clean ✅

Repro confirmation

I temporarily reverted the patch and ran the new dict-fallback test. It produced the exact error from the issue:

Error: Objects are not valid as a React child (found: object with keys {model, api_key, extra_headers}).

With the patch applied the same render shows the model name, an override tag, and a masked-JSON tooltip — no crash.

Screenshots / Proof of Fix

(Vitest output rather than screenshots, since the proof is a render-crash assertion):

✓ src/.../Fallbacks.test.tsx (20 tests) 663ms
  ✓ Fallbacks > dict-shaped fallback chain entries > renders without crashing when a fallback chain entry is a dict
  ✓ Fallbacks > dict-shaped fallback chain entries > marks dict fallback entries with an override tag
  ✓ Fallbacks > dict-shaped fallback chain entries > renders mixed string and dict entries in the same chain
  ✓ Fallbacks > dict-shaped fallback chain entries > preserves dict fallbacks when deleting a sibling fallback row
  ✓ Fallbacks > dict-shaped fallback chain entries > does not leak api_key into the rendered DOM

Test Files  1 passed (1)
     Tests  20 passed (20)

shubham-arora-clear and others added 6 commits April 23, 2026 21:54
…rriAI#25855)

Bedrock enforces non-increasing TTL ordering across cache_control blocks
(tools → system → messages). The tool cache_control TTL was being
unconditionally dropped to the default 5m, while system blocks preserved
the user-specified TTL for Claude 4.5+ models. This mismatch caused
"a ttl='1h' block must not come after a ttl='5m' block" errors when
users set ttl='1h' on both tools and system.

Converse path: add_cache_point_tool_block() now accepts a model param
and preserves TTL for Claude 4.5+, matching _get_cache_point_block().

Invoke path: _remove_ttl_from_cache_control() now also processes tools
(was only processing system and messages).

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…onses (BerriAI#20270) (BerriAI#26262)

* fix(proxy): invoke post-call guardrails on pass-through endpoint responses (BerriAI#20270)

Wire post_call_success_hook into non-streaming pass-through response path,
gated on explicit guardrail config (opt-in only, no backwards-compat break).

- Call post_call_success_hook after reading non-streaming response body
- Build enriched hook_data with guardrails metadata and litellm_logging_obj
  at call site (avoids mutation of _parsed_body which is shared by logging)
- Handle ModifyResponseException with provider-agnostic error envelope,
  post_call_failure_hook, and defensive try/except
- Strip stale content-length when guardrail modifies response body
- Move ModifyResponseException to litellm.exceptions to break cyclic import;
  re-export from custom_guardrail for backwards compat
- Add call_type fallback in UnifiedLLMGuardrails for pass-through endpoints
  using CallTypes.pass_through.value enum

* test: add unit tests for pass-through post-call guardrails

5 tests covering the post-call guardrail invocation on pass-through endpoints:
- post_call_success_hook fires when guardrails configured
- post_call_success_hook skipped when no guardrails (backwards compat)
- ModifyResponseException returns 200 with provider-agnostic error
- UnifiedLLMGuardrails resolves call_type from logging_obj for pass-through
- ModifyResponseException re-export from custom_guardrail stays in sync
…BerriAI#26122)

tool_calls on assistant messages were translated to OllamaToolCall format
but never copied into the outgoing OllamaChatCompletionMessage, so Ollama
received {role: assistant, content: ''} with no tool_calls. The model
then had no record of having made a tool call, causing it to re-issue
the identical call on every turn (infinite loop).

Similarly, tool_call_id on role:tool messages was silently dropped.
Ollama uses this field to resolve the tool name from conversation history.

Also add tool_call_id to OllamaChatCompletionMessage TypedDict.

Fixes BerriAI#26094
@veria-ai

veria-ai Bot commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

Low: Formatting and UI fix for dict-shaped fallback entries

This PR is mostly formatting changes across Python files, plus a UI fix to properly render dict-shaped fallback entries in router settings. The new masking logic for sensitive keys in fallback override dicts is client-side only and covers the common cases (string values for keys matching api_key, token, secret, password, authorization). The data already arrives at the authenticated admin client from the server, so the masking is a cosmetic defense-in-depth measure. No exploitable security issues found.


Status: 0 open
Risk: 2/10

Posted by Veria AI · 2026-04-25T19:56:11.551Z

@jayy-77
jayy-77 force-pushed the fix/router-settings-ui-dict-fallbacks branch from 979fddd to ba93eba Compare April 25, 2026 19:36
@jayy-77
jayy-77 changed the base branch from main to litellm_oss_branch April 25, 2026 19:36
@codspeed

codspeed Bot commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

Congrats! CodSpeed is installed 🎉

🆕 16 new benchmarks were detected.

You will start to see performance impacts in the reports once the benchmarks are run from your default branch.

Detected benchmarks


Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Apr 25, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a React error #31 crash in the router-settings Fallbacks UI when router_settings.fallbacks contains dict-shaped chain entries (used to override api_key/Authorization on fallback attempts). The fix widens the FallbackChainItem type, moves ChainCard to module level, adds secret-masking for tooltip and display-label display, and covers the new paths with 7 vitest regression cases. The three Python-file changes are purely cosmetic line-length reformats with no logic impact.

Confidence Score: 5/5

Safe to merge — no P0/P1 findings; both previously flagged issues are fully addressed.

All changes are well-scoped: the UI crash fix is correct, ChainCard is now at module level, secret masking covers both the tooltip and the display-label (including the no-model-field edge case). Seven tests lock in the regressions. Python file changes are formatting-only with zero logic impact.

No files require special attention.

Important Files Changed

Filename Overview
ui/litellm-dashboard/src/components/Settings/RouterSettings/Fallbacks/Fallbacks.tsx Core fix: widened FallbackChainItem type, moved ChainCard to module level, added maskSensitiveOverrideValues and getFallbackChainItemDisplayName; both previously flagged issues (secret leak in label, component-in-render) are resolved.
ui/litellm-dashboard/src/components/Settings/RouterSettings/Fallbacks/Fallbacks.test.tsx Adds 7 new regression tests (PR description says 5) covering the crash fix, override badge, mixed entries, round-trip safety, and secret masking including the no-model-field edge case; existing tests reformatted but logic unchanged.
litellm/litellm_core_utils/prompt_templates/factory.py Cosmetic reformatting of .format() call to satisfy line-length linting; no logic change.
litellm/llms/predibase/chat/transformation.py Cosmetic reformatting of long conditionals and a for-loop expression to meet line-length limits; no logic change.
litellm/proxy/guardrails/guardrail_hooks/xecguard/xecguard.py Reformatted long boolean condition and added missing trailing newline; no logic change.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["FallbackChainItem\n(string | FallbackOverride)"] --> B{typeof item}
    B -->|string| C["displayName = item"]
    B -->|object| D{item.model\nexists?}
    D -->|yes| E["displayName = item.model"]
    D -->|no| F["displayName =\nJSON.stringify(\n  maskSensitiveOverrideValues(item)\n)"]
    C --> G["ChainCard: plain span\n(no override badge)"]
    E --> H["ChainCard: span + override Tag"]
    F --> H
    H --> I["Tooltip with\nmaskSensitiveOverrideValues(item)\nas JSON preview"]
    G --> J["Rendered in\nrenderFallbacksChain"]
    I --> J
Loading

Reviews (3): Last reviewed commit: "chore: apply black formatting to unblock..." | Re-trigger Greptile

@jayy-77
jayy-77 force-pushed the fix/router-settings-ui-dict-fallbacks branch from ba93eba to 1d63c91 Compare April 25, 2026 19:39
@codecov

codecov Bot commented Apr 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.90110% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...y/pass_through_endpoints/pass_through_endpoints.py 84.61% 4 Missing ⚠️
...xy/guardrails/guardrail_hooks/xecguard/xecguard.py 99.60% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

jayy-77 added 2 commits April 26, 2026 01:22
Router runtime accepts dict chain items like
{model, api_key, extra_headers, ...} (used to override request-level
auth on a fallback attempt). Admin UI typed each item as `string` and
rendered it directly as a React child, crashing the router settings
page with React error BerriAI#31 ("Objects are not valid as a React child
(found: object with keys {model, api_key, extra_headers})").

Widen FallbackChainItem to `string | {model?: string, ...}`, derive a
display name, tag dict entries with an "override" badge, and surface
the override JSON via a tooltip with api_key / authorization / token /
secret / password (and matching extra_headers keys) masked so secrets
never enter the DOM. Add/delete flows already preserved unrelated
entries, so dict items round-trip safely with no backend changes.

Adds 5 regression tests in Fallbacks.test.tsx covering: no-crash
render, override marker, mixed string+dict chains, sibling-row delete
preserves dict entries, and api_key masking in DOM.

Fixes BerriAI#26473
Three files on litellm_oss_branch are not black-formatted, which fails
the lint check on every PR. Apply black with no functional changes.
Same pattern as aefb54f.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants