From 4962c1d62a97d5ab8506adb616e0db4149e9edb9 Mon Sep 17 00:00:00 2001 From: Praveen Ghuge Date: Sun, 26 Apr 2026 21:52:53 +0530 Subject: [PATCH] fix(mavvrik): fix dry_run TypeError on NULL spend and missing column guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug 1: float(df["spend"].sum()) raises TypeError when all spend values are NULL — polars .sum() returns None for an all-null series. Fix: float(df["spend"].sum() or 0.0) Bug 2: df["completion_tokens"].sum() accessed without checking the column exists — only "prompt_tokens" was guarded. Raises ColumnNotFoundError if schema omits completion_tokens. Fix: guard both columns together before summing. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- litellm/integrations/mavvrik/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/litellm/integrations/mavvrik/__init__.py b/litellm/integrations/mavvrik/__init__.py index 40ad45eeb65..7d9a8d58571 100644 --- a/litellm/integrations/mavvrik/__init__.py +++ b/litellm/integrations/mavvrik/__init__.py @@ -387,10 +387,10 @@ class Service: }, } - total_cost = float(df["spend"].sum()) if "spend" in df.columns else 0.0 + total_cost = float(df["spend"].sum() or 0.0) if "spend" in df.columns else 0.0 total_tokens = ( int((df["prompt_tokens"].sum() or 0) + (df["completion_tokens"].sum() or 0)) - if "prompt_tokens" in df.columns + if "prompt_tokens" in df.columns and "completion_tokens" in df.columns else 0 ) unique_models = df["model"].n_unique() if "model" in df.columns else 0