fix(proxy): coerce numeric budget settings from env var to float - #26867
fix(proxy): coerce numeric budget settings from env var to float#26867xr843 wants to merge 1 commit into
Conversation
Merging this PR will not alter performance
Comparing |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Greptile SummaryThis PR fixes a startup
Confidence Score: 4/5Safe to merge after fixing the The litellm/proxy/proxy_server.py — the
|
| Filename | Overview |
|---|---|
| litellm/proxy/proxy_server.py | Adds _coerce_budget_setting helper and uses it for all five numeric budget keys; the default_max_internal_user_budget branch has a logic flaw where the max_internal_user_budget propagation step runs even when coerced_default is None. |
| tests/test_litellm/proxy/test_max_budget_env_var.py | Adds regression tests for the config.yaml env-var budget coercion path, covering all affected keys and direct unit tests of the helper. |
Reviews (2): Last reviewed commit: "fixup: extend safe coercion to internal ..." | Re-trigger Greptile
|
Pushed |
|
I noticed this was closed unmerged. Was this superseded by another change, or would you prefer a narrower follow-up PR against the current staging branch? The original failure mode was the env-var string path for numeric budget settings, and the branch had local regression coverage for the affected budget fields. I can rework or reopen if this is still wanted. |
|
Hi, sorry this was closed automatically because the litellm_oss_staging branch was auto-deleted after it was merged in. We've since disabled auto-deletion of branches. Reopening |
Numeric budget settings (max_budget, max_user_budget, max_end_user_budget, max_internal_user_budget, default_max_internal_user_budget) may arrive as strings when loaded via os.environ/... in config.yaml. Coerce them to float via a shared _coerce_budget_setting helper so downstream numeric comparisons don't raise TypeError. Empty/whitespace env vars resolve to the unset default. See GitHub issue BerriAI#26696.
6ec0065 to
6970f34
Compare
|
Thanks for reopening, @mateo-berri 🙏 Rebased onto the current All five budget settings ( |
|
Heads-up on the two red checks — both are pre-existing/infra and unrelated to this diff (which touches only
The two |
Summary
Closes #26696. When
litellm_settings.max_budget: os.environ/MAX_BUDGETis used in config.yaml, the env var resolves to a string and the litellm_settings loop falls through to the genericsetattr(litellm, key, value), leavinglitellm.max_budgetas astr. The startup checklitellm.max_budget > 0(proxy_server.py:924) then raisesTypeError.The earlier fix (#23843 / #23855) only covered the CLI path (
initialize(max_budget=...)), not config.yaml.Changes
litellm/proxy/proxy_server.py: add explicitelifbranches in the litellm_settings loop formax_budget,max_user_budget, andmax_end_user_budget. Each coerces tofloat(value), preservingNonefor the twoOptional[float]settings.tests/test_litellm/proxy/test_max_budget_env_var.py: new regression test for the config.yaml path (test_max_budget_from_config_yaml_env_var) plus a parametrized test coveringmax_user_budgetandmax_end_user_budget(the symmetric defect — both areOptional[float]inlitellm/__init__.pyand used in numeric comparisons inlitellm/proxy/utils.py).Test plan
pytest tests/test_litellm/proxy/test_max_budget_env_var.py -v→ 5/5 passAssertionError: ... got str), confirming they catch the bugtest_max_budget_string_converted_to_float,test_max_budget_float_stays_float)Notes
max_user_budget/max_end_user_budgetinto the same PR rather than as a follow-up — both have identical failure mode, the fix is one line per key, and they share the same test pattern.proxy_server.py:5885which is also a barefloat(). Can be a separate hardening PR if desired.