Skip to content

Fix mypy regression: TypedDict key error in fireworks_ai transformation - #20391

Merged
ishaan-jaff merged 1 commit into
mainfrom
litellm_fix_mypy_regression_20260204
Feb 4, 2026
Merged

Fix mypy regression: TypedDict key error in fireworks_ai transformation#20391
ishaan-jaff merged 1 commit into
mainfrom
litellm_fix_mypy_regression_20260204

Conversation

@ghost

@ghost ghost commented Feb 4, 2026

Copy link
Copy Markdown

Regression Fix

Failing Job: mypy_linting
Caused By: #20334 (commit 3765d88)
Author: @sameer-berri

What Broke

PR #20334 added code to remove provider_specific_fields from messages before sending to FireworksAI. The code calls message.pop("provider_specific_fields", None) where message is typed as AllMessageValues (a Union of TypedDicts).

mypy correctly complained that none of the TypedDicts in the union have a provider_specific_fields key:

llms/fireworks_ai/chat/transformation.py:242: error: TypedDict "ChatCompletionUserMessage" has no key "provider_specific_fields"  [typeddict-item]
llms/fireworks_ai/chat/transformation.py:242: error: TypedDict "ChatCompletionAssistantMessage" has no key "provider_specific_fields"  [typeddict-item]
... (6 total errors)

This Fix

Cast message to dict before calling pop(). This is safe because:

  1. The code already checks isinstance(message, dict) before reaching this line
  2. The code already checks "provider_specific_fields" in message before popping

This is consistent with line 239 which already uses cast(dict, message) for filter_value_from_dict().

Cast message to dict before calling pop() to satisfy mypy's type checker.
The message is typed as a Union of TypedDicts which don't have the
'provider_specific_fields' key, but the runtime check already confirms
it's a dict with this key.
@vercel

vercel Bot commented Feb 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 4, 2026 4:46am

Request Review

@CLAassistant

CLAassistant commented Feb 4, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Shin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Feb 4, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR fixes a mypy type error introduced in PR #20334. The error occurred because message.pop("provider_specific_fields", None) was called on a variable typed as AllMessageValues (a Union of TypedDicts), none of which define the provider_specific_fields key.

The fix adds cast(dict, message) before calling .pop(), which is safe because:

  • The code already validates isinstance(message, dict)
  • The code checks "provider_specific_fields" in message before popping
  • This pattern is consistent with line 238 which uses cast(dict, message) for filter_value_from_dict()

This is a minimal, type-safe fix that resolves the mypy regression without changing runtime behavior.

Confidence Score: 5/5

  • This PR is safe to merge - it's a minimal type annotation fix with no runtime changes
  • The change only adds a type cast to satisfy mypy. The runtime behavior is unchanged, proper validation is already in place, and the pattern matches existing code on line 238
  • No files require special attention

Important Files Changed

Filename Overview
litellm/llms/fireworks_ai/chat/transformation.py Added cast(dict, message) to fix mypy type error when calling .pop() on AllMessageValues union type

Sequence Diagram

sequenceDiagram
    participant Caller
    participant FireworksAIConfig
    participant TypeChecker as mypy Type Checker
    
    Caller->>FireworksAIConfig: _transform_messages_helper(messages)
    Note over FireworksAIConfig: messages: List[AllMessageValues]
    
    loop For each message
        FireworksAIConfig->>FireworksAIConfig: Check if isinstance(message, dict)
        FireworksAIConfig->>FireworksAIConfig: Check if "provider_specific_fields" in message
        
        alt Has provider_specific_fields
            Note over FireworksAIConfig,TypeChecker: Before fix: message.pop() fails type check
            Note over FireworksAIConfig,TypeChecker: After fix: cast(dict, message).pop() passes
            FireworksAIConfig->>FireworksAIConfig: cast(dict, message).pop("provider_specific_fields", None)
        end
    end
    
    FireworksAIConfig-->>Caller: Return cleaned messages
Loading

@greptile-apps greptile-apps 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.

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@ishaan-jaff
ishaan-jaff merged commit d1994a1 into main Feb 4, 2026
58 of 66 checks passed
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
Cast message to dict before calling pop() to satisfy mypy's type checker.
The message is typed as a Union of TypedDicts which don't have the
'provider_specific_fields' key, but the runtime check already confirms
it's a dict with this key.
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.

2 participants