
    )#h-                         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                 e/var/www/html/sandstorm/venv/lib/python3.12/site-packages/litellm/proxy/guardrails/init_guardrails.pyinitialize_guardrailsr8      s   0""%CDUCV#WX% 		FD
 

 F1!.!E!E1!E%%n57E11!4F		F  #u#% ' 	ZI &&y'?'?@ &&y';';<$++I,C,CD##t+ ) 3 3 ZHw'8'88,00: --5#z1DRTXCY4Z@Z	Z  %))=$>!()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 ]  }|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!                  |       nq|d   t        j0                  j                  k(  r?ddlm}  ||d   |d   |d
   |d         }t        j                  j!                  |       n|d   t        j6                  j                  k(  rddlm}  ||d
   |d   |d   |d   |j/                  d      xs d       }|d   du rI |d|d
   t<        j>                  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        jF                  j                  k(  rwddl$m%} |j/                  d      }|tM        d        ||j/                  d      |t        jF                  j                  !      }t        j                  j!                  |       nQtO        |d   t              r,d"|d   v r$|tM        d#      dd l(}|d   }|jS                  d"      \  }}t        j                  d$|||       |jT                  jW                  |      }|jT                  jY                  ||      }|d%z  }tZ        j\                  j_                  ||      }|ta        d&|       tZ        j\                  jc                  |      } |jd                  jg                  |        ti        | |      }! |!|d
   |d   '      }"t        j                  j!                  |"       ntk        d(|d          tm        |d
   |)      }#|j!                  |#       |d
     to        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;   )AimGuardrail)_OPTIONAL_PresidioPIIMaskingoutput_parse_piipresidio_ad_hoc_recognizersmock_redacted_text)r   r@   rG   rH   rI   T)rG   r   r@   rH   )_ENTERPRISE_SecretDetectiondetect_secrets_config)rK   r@   r   )GuardrailsAI
guard_namezaGuardrailsAIException - Please pass the Guardrails AI guard name via 'litellm_params::guard_name')r=   rM   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   )8r   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AIM,litellm.proxy.guardrails.guardrail_hooks.aimrE   PRESIDIO1litellm.proxy.guardrails.guardrail_hooks.presidiorF   r
   	post_callHIDE_SECRETS,enterprise.enterprise_hooks.secret_detectionrJ   GURDRAILS_AI6litellm.proxy.guardrails.guardrail_hooks.guardrails_airL   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   _aim_callbackrF   _presidio_callback_success_callbackrJ   _secret_detection_objectrL   _guard_name_guardrails_ai_callbackrd   
_guardrail
_file_name_class_name	directorymodule_file_pathspecmodule_guardrail_class_guardrail_callbackparsed_guardrails$                                       r7   init_guardrails_v2r   V   sH   
 N $ C$	 ((89""#79LM #22779"
 .A)A"1%tK"
 "

 '@)?@ "%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K(,J,N,N,T,TT )'
3&y1()9:)&1	M $$]3;'+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)

 	./"#GC$J 
n-R
01"
s   V=)N)ri   typingr   r   r   r    r   litellm._loggingr   )litellm.proxy.common_utils.callback_utilsr   litellm.types.guardrailsr	   r
   r   r   r   r   r   r   rP   r-   booldictr8   r   r       r7   <module>r      s     ' '   1 S   ')]# (6D&7!78966 6 	6
 
#}
6r '+M2JM2smM2r   