
    g+                         U d dl Z d dlmZmZmZ d dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZmZmZmZ g aee   ed<   deeeef      d	ed
ededeeef   f
dZ	 	 ddee   d
ee   fdZy)    N)DictListOptional)
get_secret)verbose_proxy_logger)initialize_callbacks_on_proxy)	GuardrailGuardrailEventHooksGuardrailItemGuardrailItemSpecLakeraCategoryThresholdsLitellmParamsSupportedGuardrailIntegrationsall_guardrailsguardrails_configpremium_userconfig_file_pathlitellm_settingsreturnc                 r   	 t        j                  d|         | D ]R  }	 |j                         D ]<  \  }}t        d	i |d|i}t        j                  |       |t        j                  |<   > T t               }i }	t        D ]  }
t        j                  |
j                         t        j                  |
j                         |	j                  |
j                         |
j                  du sk|
j                  D ]A  }|t        j                  vr|j                  |       |
j                  du s5|dk(  s;ddi|	d<   C  t!        |      }t#        |      dkD  rt%        |||||	       t        j                  S # t&        $ r4}t        j(                  dj+                  t-        |                   |d }~ww xY w)
Nzvalidating  guardrails passed guardrail_nameTpresidiologging_onlyr   )valuer   r   r   callback_specific_paramsz error initializing guardrails {} )r   debugitemsr   r   appendlitellmguardrail_name_config_mapsetr   
default_onupdatecallback_args	callbacksaddr   listlenr   	Exception	exceptionformatstr)r   r   r   r   itemkvguardrail_itemdefault_on_callbacksr   	guardrailcallbackdefault_on_callbacks_listes                 ]/var/www/openai/venv/lib/python3.12/site-packages/litellm/proxy/guardrails/init_guardrails.pyinitialize_guardrailsr8      s   0""%CDUCV#WX%D
 

1!.!E!E1!E%%n57E11!4 % &  #u#% 'I &&y'?'?@ &&y';';<$++I,C,CD##t+ ) 3 3Hw'8'88,00: --5#z1DRTXCY4Z@ !4 (  %))=$>!()A-)/)!1!1)A 000 &&.55c!f=	
 	s,   C+E9 .A E9 /E9 5AE9 9	F6/F11F6c           
      
   g }| D ]E  }|d   }t        j                  d|       t        j                  j	                         D ci c]  }|||v r||   nd  }}t        d+i |}d|v r|d   rt        d+i |d   }||d<   |d   r.|d   j                  d      rt        t        |d               |d<   |d   r.|d   j                  d      rt        t        |d               |d<   |d   t        j                  j                  k(  r?dd	lm}	  |	|d   |d   |d
   |d         }
t        j                  j!                  |
       n|d   t        j"                  j                  k(  r?ddlm}  ||d
   |d   |d   |d         }t        j                  j!                  |       n|d   t        j(                  j                  k(  rOddlm}  ||d   |d   |d
   |d   |j/                  d            }t        j                  j!                  |       n|d   t        j0                  j                  k(  rddlm}  ||d
   |d   |d   |d   |j/                  d      xs d       }|d   du rI |d|d
   t6        j8                  j                  |d         }t        j                  j!                  |       t        j                  j!                  |       nO|d   t        j:                  j                  k(  rGddlm}  ||j/                  d      |d   |d
         }t        j                  j!                  |       n|d   t        j@                  j                  k(  rwddl!m"} |j/                  d      }|tG        d       ||j/                  d      |t        j@                  j                         }t        j                  j!                  |       nQtI        |d   t              r,d!|d   v r$|tG        d"      dd l%}|d   }|jM                  d!      \  }}t        j                  d#|||       |jN                  jQ                  |      }|jN                  jS                  ||      }|d$z  }tT        jV                  jY                  ||      }|t[        d%|       tT        jV                  j]                  |      }|j^                  ja                  |       tc        ||      } ||d
   |d   &      } t        j                  j!                  |        nte        d'|d          tg        |d
   |(      }!|j!                  |!       |d
    H ti        d)| d*       y c c}w ),Nlitellm_paramszlitellm_params= %scategory_thresholdsapi_keyzos.environ/api_baser3   r   )AporiaGuardrailr   mode)r=   r<   r   
event_hook)BedrockGuardrailguardrailIdentifierguardrailVersion)r   r@   rB   rC   )lakeraAI_Moderation)r=   r<   r   r@   r;   )_OPTIONAL_PresidioPIIMaskingoutput_parse_piipresidio_ad_hoc_recognizersmock_redacted_text)r   r@   rF   rG   rH   T)rF   r   r@   rG   )_ENTERPRISE_SecretDetectiondetect_secrets_config)rJ   r@   r   )GuardrailsAI
guard_namezaGuardrailsAIException - Please pass the Guardrails AI guard name via 'litellm_params::guard_name')r=   rL   r   .zTGuardrailsAIException - Please pass the config_file_path to initialize_guardrails_v2z@Initializing custom guardrail: %s, file_name: %s, class_name: %sz.pyz*Could not find a module specification for )r   r@   zUnsupported guardrail: )r   r:   z
Guardrail List:
r   )5r   r   r   __annotations__keysr   
startswithr-   r   r   APORIAr   2litellm.proxy.guardrails.guardrail_hooks.aporia_air>   r    r&   r   BEDROCK;litellm.proxy.guardrails.guardrail_hooks.bedrock_guardrailsrA   LAKERA2litellm.proxy.guardrails.guardrail_hooks.lakera_airD   getPRESIDIO1litellm.proxy.guardrails.guardrail_hooks.presidiorE   r
   	post_callHIDE_SECRETS,enterprise.enterprise_hooks.secret_detectionrI   GURDRAILS_AI6litellm.proxy.guardrails.guardrail_hooks.guardrails_airK   r*   
isinstanceossplitpathdirnamejoin	importlibutilspec_from_file_locationImportErrormodule_from_specloaderexec_modulegetattr
ValueErrorr	   print)"r   r   guardrail_listr3   litellm_params_datar/   _litellm_params_kwargsr:   lakera_category_thresholdsr>   _aporia_callbackrA   _bedrock_callbackrD   _lakera_callbackrE   _presidio_callback_success_callbackrI   _secret_detection_objectrK   _guard_name_guardrails_ai_callbackra   
_guardrail
_file_name_class_name	directorymodule_file_pathspecmodule_guardrail_class_guardrail_callbackparsed_guardrails"                                     r7   init_guardrails_v2r   V   s   
 N $	 ((89""#79LM #22779"
9 .A)A"1%tK9 	 "

 '@)?@ "%88#$9:)A *%&;<*& 5ON01)$i(33MB,/
>);T0U,Vy)*%j)44]C-0N:<V1W-Xz* +&*H*O*O*U*UU  /'
3&y1()9:)&1	  $$%56;'+I+Q+Q+W+WW !1()9:)&1$23H$I!/0B!C	! $$%67K(,J,Q,Q,W,WW  3'
3&y1()9:)&1$2$6$67L$M  $$%56;'+I+R+R+X+XX ">()9:)&1!/0B!C,:1- $2#5#56J#K#St" 01T9$@%)#,-=#>2<<BB0>51	%! !!(():;$$%78;'-::@@A (C&4&8&89P&Q)&1()9:($ $$%=>;'-::@@A ),,\:K"w  '3'++J7&=JJPP'# $$%<=~k2C8~k22'j   (4J&0&6&6s&;#J &&R	 (89I!ww||IzB%>>99+GWXD|!@AQ@RS  ^^44T:FKK##F+&v{;"2()9:)&1# $$%896~k7R6STUU$$%56)

 	./"#o $r 
n-R
01g"
s   U)N)rf   typingr   r   r   r    r   litellm._loggingr   )litellm.proxy.common_utils.callback_utilsr   litellm.types.guardrailsr	   r
   r   r   r   r   r   r   rO   r-   booldictr8   r   r       r7   <module>r      s     ' '   1 S   ')]# (6D&7!78966 6 	6
 
#}
6r '+A2JA2smA2r   