Commit Graph

32 Commits

Author SHA1 Message Date
Yuneng Jiang e7f4e77af0 Bound _get_masked_values recursion depth
Add _depth/_max_depth guards (default 20) so the nested dict masking
cannot run away, and allowlist the function in the recursive_detector
CI check alongside the other bounded recursive helpers.
2026-04-24 13:00:33 -07:00
yuneng-jiang a93c069dd5 [Fix] Add max_depth guard to BFL _read_image_bytes recursive function
Use the standard depth/max_depth pattern with DEFAULT_MAX_RECURSE_DEPTH
to guard the recursive list-unwrapping in _read_image_bytes, matching
the existing pattern used by _read_all_bytes in vertex_imagen.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-12 13:22:56 -07:00
Ishaan Jaffer add3183308 IGNORE_FUNCTIONS 2026-02-14 12:59:15 -08:00
Alexsander Hamir ebce0e5f8c [Release - 02/10/2026] v1.81.10-nightly 2026-02-10 16:26:30 -08:00
Krish Dholakia 7056d9984e Custom Code Guardrails UI Playground (#20377)
* feat(guardrails/): allow custom code execution for guardrails

first step in allowing teams to submit custom code for guardrails

* feat: custom_code_guardrail.md

support passing custom code for guardrails

* feat: initial commit adding ui for custom code guardrails

allows users to write guardrails based on custom code

* feat: expose new test custom code guardrail endpoint

allows ui testing playground to sanity check if guardrail is working as expected

* fix: fix linting errors

* fix: fix max recursion check

* fix: fix linting error
2026-02-03 19:57:24 -08:00
Ishaan Jaff 9ed11c5cdf [Feat] Allow calling A2A agents through LiteLLM /chat/completions API (#20358)
* init A2AConfig

* add transform files

* feat: A2A

* feat A2AConfig

* fix get_secret_str

* init: A2AConfig

* init A2AConfig common utils

* A2AConfig

* test_a2a_completion_async_non_streaming

* fix

* Update litellm/main.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

* add multi part conversation support

* extract_text_from_a2a_message

---------

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-03 12:52:33 -08:00
Ishaan Jaff c23e4b87dc [Feat] New LiteLLM Policy engine - create policies to manage guardrails, conditions - permissions per Key, Team (#19612)
* init PolicyMatcher

* TestPolicyMatcherGetMatchingPolicies

* TestPolicyMatcherGetMatchingPolicies

* feat: init PolicyResolver

* init resolver types

* init policy from config

* inint PolicyValidator

* validate policy

* init Architecture Diagram

* test_add_guardrails_from_policy_engine

* init _init_policy_engine

* test updates

* test fixws

* new attachment config

* simplify types

* TestPolicyResolverInheritance

* fix policy resolver

* fix policies

* fix applied policy

* docs fix

* docs fix

* fix linting + QA checks

* fix linting + QA fixes

* test fixes
2026-01-22 19:49:53 -08:00
Ishaan Jaffer e3fe02148d _mask_sequence 2026-01-10 13:20:43 -08:00
Alexsander Hamir a7da4833da [Fix] CI/CD - check_code_and_doc_quality (#18560) 2026-01-01 11:18:59 -08:00
Alexsander Hamir 892d7e8d70 [Fix] CI/CD - Fix Bedrock tool calling test failures with non-serializable objects and internal parameters (#17930)
* fix(bedrock): filter non-serializable objects from request params

- Enhanced filter_exceptions_from_params() to filter callable objects (functions) and Logging objects
- Applied filtering in Bedrock's _prepare_request_params() before deepcopy
- Applied filtering to additional_request_params before JSON serialization
- Prevents TypeError during deepcopy (APIConnectionError objects) and JSON serialization (functions, Logging objects)
- Fixes test_bedrock_tool_calling test failures

Root cause: MCP-related functions (handle_chat_completion_with_mcp, completion_callable) and litellm_logging_obj were incorrectly added to optional_params via add_provider_specific_params_to_optional_params(), which then ended up in additional_request_params. These objects should be in litellm_params, not optional_params.

* fix(bedrock): filter internal MCP parameters from API requests

Filter out LiteLLM internal/MCP-related parameters (skip_mcp_handler,
mcp_handler_context, _skip_mcp_handler) from additional_request_params
before sending to Bedrock API to prevent 'extraneous key' errors.

- Added filter_internal_params() helper function in core_helpers.py
- Applied filtering in Bedrock's _prepare_request_params() method
- Fixes test_bedrock_completion.py::test_bedrock_tool_calling

* fix: mypy type error

* fix: add filter_exceptions_from_params to recursive function ignore list

- Add filter_exceptions_from_params to IGNORE_FUNCTIONS in recursive_detector.py
- Function is safe: has max_depth parameter (default 20) to prevent infinite recursion
2025-12-13 12:38:07 -08:00
Sameer Kankute b39c21d90c fix: Add _delete_nested_value_custom to recursive function ignore list
The _delete_nested_value_custom function is recursive but has bounded depth
(limited by the number of path segments), preventing infinite recursion.
This is necessary for nested field removal in additional_drop_params.
2025-12-09 17:56:13 +05:30
Ishaan Jaff 5c192a23c3 [Feat] Add new RAG API on LiteLLM AI Gateway (#17109)
* init RAG api types

* add RAG endpoints

* init main.py for RAG ingest API

* init RecursiveCharacterTextSplitter

* add BaseRAGIngestion

* fix OpenAIRAGIngestion

* fix img handler

* init OpenAIRAGIngestion

* init BedrockRAGIngestion

* init BedrockRAGIngestion

* init rag tests

* init BedrockVectorStoreOptions

* implement BedrockRAGIngestion

* add BaseRAGAPI

* add endpoint for RAG ingest

* add ingest RAG endpoints

* add test doc

* add parse_rag_ingest_request

* update endpoints

* docs add docs for new RAG API

* fix qa check

* fix linting

* docs ficx

* docs

* add max depth checks

* docs anthropic
2025-11-25 17:54:29 -08:00
yuneng-jiang 4b25398afe [Infra] CI/CD Fixes (#16937)
* Attempt CI/CD Fix

* Adding test for coverage

* Adding max depth to copilot and vertex

* Fixing mypy lint and docker database

* Fixing UI build issues

* Update playwright test
2025-11-21 13:58:19 -08:00
Ishaan Jaffer d32890ba55 fix _redact_base64 2025-10-28 17:38:16 -07:00
Ishaan Jaff f1699d4cbf fix IGNORE_FUNCTIONS 2025-09-08 17:33:36 -07:00
Ishaan Jaff 4c7b3e10ed [Bug Fix] Gemini Tool Calling - fix gemini empty enum property (#14155)
* fix: _convert_schema_types

* fix recursive detector

* test_convert_schema_types_type_array_conversion

* fix: DEFAULT_NUM_WORKERS_LITELLM_PROXY

* add _fix_enum_empty_strings

* test_tool_call_with_empty_enum_property

* test_fix_enum_empty_strings

* fix _fix_enum_empty_strings
2025-09-01 17:05:01 -07:00
Ishaan Jaff 2331fb45d5 [Bug]: Gemini 2.5 Pro – schema validation fails with OpenAI-style type arrays in tools (#14154)
* fix: _convert_schema_types

* fix recursive detector

* test_convert_schema_types_type_array_conversion

* fix: DEFAULT_NUM_WORKERS_LITELLM_PROXY
2025-09-01 16:53:20 -07:00
Ishaan Jaff 621b3dca7b [Bug Fix] Mistral Tool Calling - Grammar error: at 3(11): failed to compile JSON schema (#13389)
* test_claude_tool_use_with_gemini

* add _remove_json_schema_refs

* add _clean_tool_schema_for_mistral

* fixes mistral tool calls

* _remove_json_schema_refs

* fix - vertex, remove hardcoded test
2025-08-07 13:50:22 -07:00
Krish Dholakia e7f1fa26ab UI - Azure Content Guardrails (#12341)
* build(model_prices_and_context_window.json): remove 'supports_tool_choice' for specific mistral models

Closes https://github.com/BerriAI/litellm/issues/11750

* feat: initial commit adding cleaner ui for azure text moderation guardrails

* feat(guardrail_endpoints.py): add discoverable guardrail configs and improve converting base model to dict with types

* fix(guardrail_provider_fields.tsx): render from api endpoint correctly

* fix(guardrail_provider_fields.tsx): cleanup

* refactor(guardrail_endpoints.py): refactor to handle dictionaries with literal - allows multiselect

* feat(ui/): render dictionary with known keys correctly

* feat(ui/): render optional params on separate page

* style(ui/): style improvements to rendering optional params on the UI

* feat(azure/prompt_shield.py): add azure prompt shield back on UI

* fix(add_guardrail_form.tsx): fix form to handle updated api

* fix(guardrail_optional_params.tsx): ensure values are nested correctly for writing to api

* fix: fix linting error

* feat(text_moderation.py): handle str to int conversion

* fix(guardrail_info.tsx): only render pii settings if guardrail is presidio

* fix(guardrail_info.tsx): add guardrail specific fields to update settings

allows updating guardrail fields (e.g. severity threshold) post-create

* fix(guardrail_endpoints.py): set guardrail_id in guardrail object

ensures duplicate objects not created on guardrail update

* fix(guardrail_endpoints.py): allow provider specific fields to be updated on patch update

* refactor(guardrail_endpoints.py): remove duplicate info endpoint

* fix(guardrail_endpoints.py): mask sensitive keys on returning via guardrail `/info`

Prevent leaking keys

* fix(guardrail_optional_params.tsx): return numerical input when numerical component used

fixes issue where output was a str

* fix(guardrail_optional_params.tsx): render dict keys correctly

* fix(text_moderation.py): fix severity by category check

* fix(proxy/utils.py): check if guardrail should run for post call streaming hook

Prevents invalid guardrails from running if not requested

* test: fix import

* fix: fix linting error

* test: update test

* fix: fix tests

* fix: fix code qa errors

* fix(guardrail_endpoints.py): set max depth for function

* test: update recursive_detector.py

* test: update list

* build: merge main

* fix: fix ruff check errors
2025-07-05 10:19:29 -07:00
Ishaan Jaff f1c7024e70 [Feat] Add Bridge from generateContent <> /chat/completions (#12081)
* add GenerateContentToCompletionHandler

* working - non streaming bridge

* add GoogleGenAIAdapter

* add google gen ai adapter

* working streaming bridge

* working streaming usage for adapter

* tool calling transform for generate content to openai

* fixes for accumulating tool calls

* fix code qa checks

* Best Practices for Production

* fix code qa checks

* test_streaming_partial_tool_calls_accumulation

* linting fixes

* add supported_openai_chat_completion_params

* fix translate_generate_content_to_completion

* test_google_genai_adapter.py
2025-06-27 11:08:55 -07:00
Krish Dholakia 06484f6e5a Xai, VertexAI, Google AI Studio - live web search support in OpenAI format (#11251)
* build(model_prices_and_context_window.json): fix 'supports_web_search' flag - openai only supports it on 2 models - gpt-4o-search-preview and gpt-4o-mini-search-preview

* feat(xai/chat): add xai web search options param support

* test: add max tokens to test

xai output very verbose

* build(xai/): add web search support for all xai models

* build(model_prices_and_cost.json): add gemini-2.0 supports web search

* feat(gemini/): map openai 'web_search_options' to google's 'googlesearch' tool

* build(model_prices_and_context_window.json): add supports_web_search for vertex_ai/gemini-2 models

* fix: fix circular reference error

* fix(convert_dict_to_response.py): handle scenario where xai returns finish reason as 'stop' for tool calls

* fix: reduce function size

* fix: import session handling

* Revert "fix: import session handling"

This reverts commit deb257dc10.

* fix: linting pin mypy

* [Feat]: Guardrails - Add streaming for bedrock post guard (#11247)

* feat: add streaming for bedrock post guard

* fix: bedrock guardrails

* fix: add clear comments

* Update litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* Update litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* fix: clean up bedrock guardrails

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* [Fix] Responses API - Session management  (#11254)

* fix: import session handling

* fix: imports for session handler

* tests: tests for session handler

* Update enterprise/litellm_enterprise/enterprise_callbacks/session_handler.py

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

* bump: bump litellm enterprise

* fixes: test_create_user_default_budget

* fix(xai/): filter 'strict' on tool call

* test: update test for new error string

* fix(utils.py): default to None if not set in  model cost map

ensures consistent usage of 'supports_[x]' flags

* fix(fireworks_ai/): support fireworks ai document inlining on pdf's sent via openai 'file' message type

* test: update test

* test: name filter_value_from_dict

* fix(fireworks_ai/): handle cache control flag in messages

* fix(xai/chat): fix check

---------

Co-authored-by: Ishaan Jaff <ishaanjaffer0324@gmail.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-05-31 14:26:16 -07:00
Krish Dholakia fdfef04d93 Gemini Multimodal Live API support (#10841)
* fix: initial commit

* refactor(gemini/realtime/transformation.py): initial instrumentation

* fix: fix default api base if not set

* feat(gemini/): passes initial user request to backend

* feat(realtime_streaming.py): support transforming message input before sending it

enables gemini realtime streaming to be sent in correct format

* feat: initial working commit of setup message being sent + working

* fix(gemini/): initial commit supporting realtime response transformation

* feat(gemini/realtime): transform session.created event correctly

* fix(realtime_streaming.py): more gemini/realtime response mapping - handle new message

* test(gemini/realtime/test_): add more unit tests

* feat(gemini/realtime): handles consecutive deltas

* feat(gemini/realtime): support openai 'response.text.done' event

* feat(gemini/realtime): add openai 'response.text.done' and 'response.content_part.done' event support

* fix(gemini/realtime): add openai 'response.done' event support

unified realtime api support

* fix: fix linting errors

* fix: fix linting error

* fix: fix linting error

* fix: handle infinite loop

* fix: fix linting error

* fix: fix recursive detector

* fix: fix file

* fix: fix linting error

* fix: fix linting error
2025-05-15 22:39:09 -07:00
Krish Dholakia 7210b713dc Add target model name validation (#10722)
* fix(auth_checks.py): enforce auth checks on target model names

ensures user has access to models they are trying to call

* test(test_auth_utils.py): add unit tests for auth check

* fix(exception_mapping_utils.py): handle mistral 429 exception

* fix: fix linting error

* fix(auth_checks.py): add max fallback depth
2025-05-10 14:27:06 -07:00
Krish Dholakia bf9382a182 Handle more gemini tool calling edge cases + support bedrock 'stable-image-core' (#10351)
* test(test_amazing_vertex_completion.py): try to repro https://github.com/BerriAI/litellm/issues/10319

* fix(common_utils.py): handle edge case on tools

Fixes https://github.com/BerriAI/litellm/issues/10319

* test: add unit testing for infinite loops

* fix(amazon_stability3_transformation.py): support 'stable-image-core' transformation

Fixes https://github.com/BerriAI/litellm/issues/8488

* test: add unit testing for stable image core model

* test: update test
2025-04-28 14:22:29 -07:00
Krish Dholakia fdfa1108a6 Add property ordering for vertex ai schema (#9828) + Fix combining multiple tool calls (#10040)
* fix #9783: Retain schema field ordering for google gemini and vertex (#9828)

* test: update test

* refactor(groq.py): initial commit migrating groq to base_llm_http_handler

* fix(streaming_chunk_builder_utils.py): fix how tool content is combined

Fixes https://github.com/BerriAI/litellm/issues/10034

* fix(vertex_ai/common_utils.py): prevent infinite loop in helper function

* fix(groq/chat/transformation.py): handle groq streaming errors correctly

* fix(groq/chat/transformation.py): handle max_retries

---------

Co-authored-by: Adrian Lyjak <adrian@chatmeter.com>
2025-04-15 22:29:25 -07:00
Krish Dholakia 87733c8193 Fix anthropic prompt caching cost calc + trim logged message in db (#9838)
* fix(spend_tracking_utils.py): prevent logging entire mp4 files to db

Fixes https://github.com/BerriAI/litellm/issues/9732

* fix(anthropic/chat/transformation.py): Fix double counting cache creation input tokens

Fixes https://github.com/BerriAI/litellm/issues/9812

* refactor(anthropic/chat/transformation.py): refactor streaming to use same usage calculation block as non-streaming

reduce errors

* fix(bedrock/chat/converse_transformation.py): don't increment prompt tokens with cache_creation_input_tokens

* build: remove redisvl from requirements.txt (temporary)

* fix(spend_tracking_utils.py): handle circular references

* test: update code cov test

* test: update test
2025-04-09 21:26:43 -07:00
Krish Dholakia 8e3c7b2de0 fix(vertex_ai.py): move to only passing in accepted keys by vertex ai response schema (#8992)
* fix(vertex_ai.py): common_utils.py

move to only passing in accepted keys by vertex ai

prevent json schema compatible keys like $id, and $comment from causing vertex ai openapi calls to fail

* fix(test_vertex.py): add testing to ensure only accepted schema params passed in

* fix(common_utils.py): fix linting error

* test: update test

* test: accept function
2025-04-07 18:07:01 -07:00
Nicholas Grabar 1f2bbda11d Add recursion depth to convert_anyof_null_to_nullable, constants.py. Fix recursive_detector.py raise error state 2025-03-28 13:11:19 -07:00
Ishaan Jaff fff15543d9 (UI + Proxy) Cache Health Check Page - Cleanup/Improvements (#8665)
* fixes for redis cache ping serialization

* fix cache ping check

* fix cache health check ui

* working error details on ui

* ui expand / collapse error

* move cache health check to diff file

* fix displaying error from cache health check

* ui allow copying errors

* ui cache health fixes

* show redis details

* clean up cache health page

* ui polish fixes

* fix error handling on cache health page

* fix redis_cache_params on cache ping response

* error handling

* cache health ping response

* fx error response from cache ping

* parsedLitellmParams

* fix cache health check

* fix cache health page

* cache safely handle json dumps issues

* test caching routes

* test_primitive_types

* fix caching routes

* litellm_mapped_tests

* fix pytest-mock

* fix _serialize

* fix linting on safe dumps

* test_default_max_depth

* pip install "pytest-mock==3.12.0"

* litellm_mapped_tests_coverage

* add readme on new litellm test dir
2025-02-19 19:08:50 -08:00
Krish Dholakia f651d51f26 Litellm dev 02 07 2025 p2 (#8377)
* fix(caching_routes.py): mask redis password on `/cache/ping` route

* fix(caching_routes.py): fix linting erro

* fix(caching_routes.py): fix linting error on caching routes

* fix: fix test - ignore mask_dict - has a breakpoint

* fix(azure.py): add timeout param + elapsed time in azure timeout error

* fix(http_handler.py): add elapsed time to http timeout request

makes it easier to debug how long request took before failing
2025-02-07 17:30:38 -08:00
Ishaan Jaff 53a3ea3d06 (Refactor) Langfuse - remove prepare_metadata, langfuse python SDK now handles non-json serializable objects (#7925)
* test_langfuse_logging_completion_with_langfuse_metadata

* fix litellm - remove prepare metadata

* test_langfuse_logging_with_non_serializable_metadata

* detailed e2e langfuse metadata tests

* clean up langfuse logging

* fix langfuse

* remove unused imports

* fix code qa checks

* fix _prepare_metadata
2025-01-22 22:11:40 -08:00
Ishaan Jaff dd385410df (Code quality) - Ban recursive functions in codebase (#7910)
* code qa add RecursiveFunctionFinder

* test_recursive_detector

* RecursiveFunctionFinder

* fix check

* recursive_detector
2025-01-21 20:33:32 -08:00