o
    ưi
                     @   s6   d dl mZmZmZ d dlmZmZ G dd dZdS )    )ListOptionalUnion)GuardrailEventHooksModec                   @   sH   e Zd Ze	ddedeeeee e	f  dee dee
 fddZdS )	EnterpriseCustomGuardrailHelperNdata
event_hook
event_typereturnc                 C   s  ddl m} ddlm} ddlm} |std|jj d|du s't	|t
s)dS | di }|j| |d	}d}|rK|D ]}	|	|jv rJ|j|	 } nq<|durd|durbt	|tr]|j|v S |j|kS d
S |jdur|durt	|jtrv|jn|jg}
|j|
v S dS dS )a6  
        Returns True if the guardrail should be run for this request and event_type.

        Logic:
        - If a request tag matches a Mode tag key, only run if event_type matches
          the tag's value (the mode for that tag).
        - If no request tag matches, fall back to default mode(s).
        r   )StandardLoggingPayloadSetup)CommonProxyErrors)premium_userzKSetting tag based guardrail modes is only available in litellm-enterprise. .Nproxy_server_request)Zlitellm_paramsr   TF)Z*litellm.litellm_core_utils.litellm_loggingr   Zlitellm.proxy._typesr   Zlitellm.proxy.proxy_serverr   	ExceptionZnot_premium_uservalue
isinstancer   getZ_get_request_tagstagslistdefault)r   r	   r
   r   r   r   r   Zrequest_tagsZmatched_modetagZdefault_list r   g/home/app/Keep/.python/lib/python3.10/site-packages/litellm_enterprise/integrations/custom_guardrail.py_should_run_if_mode_by_tag   sH   







z:EnterpriseCustomGuardrailHelper._should_run_if_mode_by_tag)N)__name__
__module____qualname__staticmethoddictr   r   r   r   r   boolr   r   r   r   r   r      s    r   N)typingr   r   r   Zlitellm.types.guardrailsr   r   r   r   r   r   r   <module>   s    