litellm icon indicating copy to clipboard operation
litellm copied to clipboard

feat : Added a dynamic configuration in addition to the static 'litellm_para…

Open IleAuxVaches opened this issue 8 months ago • 3 comments

Title

Add dynamic configuration of litellm_params for CustomGuardrail, avoiding nested configuration elements

Pre-Submission checklist

  • [x] I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • [x] I have added a screenshot of my new test passing locally
  • [x] My PR passes all unit tests on (make test-unit)[https://docs.litellm.ai/docs/extras/contributing_code]
  • [x] My PR's scope is as isolated as possible, it only solves 1 specific problem

Tests

new

{
	"testsuites": {
		"testsuite": {
			"_name": "pytest",
			"_errors": "0",
			"_failures": "0",
			"_skipped": "0",
			"_tests": "3",
			"_time": "1.462",
			"_timestamp": "2025-04-01T16:13:18.758195",            
			"testcase": [
				{
					"_classname": "local_testing.test_custom_guardrails.TestCustomGuardrails",
					"_name": "test_missing_config_file",
					"_time": "0.260"
				},
				{
					"_classname": "local_testing.test_custom_guardrails.TestCustomGuardrails",
					"_name": "test_successful_initialization",
					"_time": "0.262"
				},
				{
					"_classname": "local_testing.test_custom_guardrails.TestCustomGuardrails",
					"_name": "test_unsupported_guardrail",
					"_time": "0.265"
				}
			],

		}
	}
}

all

image

Type

🆕 New Feature ✅ Test

Changes

LitellmParams

  • Makes all fields optional with total=False (TypedDict for Litellm parameters with support for both static and dynamic fields).
  • Maintains type checking for predefined fields.
  • Allows any additional fields through __class_getitem__.
    Preserves the original structure and purpose of the class.
    Requires no changes to existing code using LitellmParams.
    This solution gives you the flexibility to add any parameters you need while maintaining type safety for the predefined fields.

init_guardrails_v2

if isinstance(guardrail_type, str) and "." in guardrail_type:

  • Split params into known and additional parameters.
  • Instanciate dynamically CustomGuardrail.
  • Update optional parameters while preserving existing ones.

IleAuxVaches avatar Apr 01 '25 14:04 IleAuxVaches

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2025 1:35pm

vercel[bot] avatar Apr 01 '25 14:04 vercel[bot]

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

:white_check_mark: IleAuxVaches
:x: Gwendrez
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Apr 22 '25 22:04 CLAassistant

@ishaan-jaff the 2d part

superpoussin22 avatar May 05 '25 20:05 superpoussin22

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] avatar Aug 12 '25 00:08 github-actions[bot]