Ë
    tPêjÎ)  ã                   ó¨   — d dl mZmZ d dlZd dlmZ d dl­ dedefd„Z	dedefd„Z
dedefd	„Zdedefd
„Zdedefd„Zdedefd„Zdedefd„Zd„ Zy)é    )ÚAnyÚFinalN)ÚCommonProxyErrors)Ú*Úlitellm_paramsÚ	guardrailc           	      ó  — ddl m}  |di d|j                  dd«      “d| j                  “d| j                  “d| j
                  “d| j                  “d	| j                  “d
| j                  “d| j                  “d| j                  “d| j                  “d| j                  “d| j                  “d| j                  “d| j                  “d| j                   “d| j"                  “d| j$                  “d| j&                  “d| j(                  “d| j*                  “d| j,                  “d| j.                  “d| j0                  “d| j2                  “d| j4                  “d| j6                  xs d“Ž}t8        j:                  j=                  |«       |S ) Nr   )ÚBedrockGuardrailÚguardrail_nameÚ Ú
event_hookÚguardrailIdentifierÚguardrailVersionÚchecksÚcontent_filter_thresholdÚprompt_attack_thresholdÚpii_confidence_thresholdÚchunk_budget_charsÚ
default_onÚdisable_exception_on_blockÚmask_request_contentÚmask_response_contentÚaws_region_nameÚaws_access_key_idÚaws_secret_access_keyÚaws_session_tokenÚaws_session_nameÚaws_profile_nameÚaws_role_nameÚaws_web_identity_tokenÚaws_sts_endpointÚaws_external_idÚaws_bedrock_runtime_endpointÚ)experimental_use_latest_role_message_onlyÚonly_scan_new_messagesF© )Ú;litellm.proxy.guardrails.guardrail_hooks.bedrock_guardrailsr
   ÚgetÚmoder   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   ÚlitellmÚlogging_callback_managerÚadd_litellm_callback)r   r   r
   Ú_bedrock_callbacks       út/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/proxy/guardrails/guardrail_initializers.pyÚinitialize_bedrockr/   	   sÚ  € õñ  0ò  Ø —}‘}Ð%5°rÔ:ð à!×&Ò&ð ð +×>Ò>ð ð (×8Ò8ð	 ð
 ×$Ò$ð ð "0×!HÒ!Hð ð !/× FÒ Fð ð "0×!HÒ!Hð ð *×<Ò<ð ð "×,Ò,ð ð $2×#LÒ#Lð ð ,×@Ò@ð ð -×BÒBð ð '×6Ò6ð ð )×:Ò:ð ð  -×BÒBð! ð" )×:Ò:ð# ð$ (×8Ò8ð% ð& (×8Ò8ð' ð( %×2Ò2ð) ð*  .×DÒDð+ ð, (×8Ò8ð- ð. '×6Ò6ð/ ð0 &4×%PÒ%Pð1 ð2 3A×2jÒ2jð3 ð4  .×DÑDÒMÈøð5 Ðô8 ×$Ñ$×9Ñ9Ð:KÔLØÐó    c                 óð   — ddl m}  || j                  | j                  |j	                  dd«      | j
                  | j                  | j                  ¬«      }t        j                  j                  |«       |S )Nr   )ÚlakeraAI_Moderationr   r   )Úapi_baseÚapi_keyr   r   Úcategory_thresholdsr   )Ú2litellm.proxy.guardrails.guardrail_hooks.lakera_air2   r3   r4   r(   r)   r5   r   r*   r+   r,   )r   r   r2   Ú_lakera_callbacks       r.   Úinitialize_lakerar8   .   si   € ÝVá1Ø×(Ñ(Ø×&Ñ&Ø —}‘}Ð%5°rÓ:Ø!×&Ñ&Ø*×>Ñ>Ø!×,Ñ,ôÐô ×$Ñ$×9Ñ9Ð:JÔKØÐr0   c                 ó   — ddl m}  || j                  | j                  |j	                  dd«      | j
                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  | j                  ¬«      }t         j"                  j%                  |«       |S )Nr   )ÚLakeraAIGuardrailr   r   )r3   r4   r   r   r   Ú
project_idÚpayloadÚ	breakdownÚmetadataÚdev_infoÚ
on_flaggedÚ skip_system_message_in_guardrailÚskip_tool_message_in_guardrailÚadvisory_system_message)Ú5litellm.proxy.guardrails.guardrail_hooks.lakera_ai_v2r:   r3   r4   r(   r)   r   r;   r<   r=   r>   r?   r@   rA   rB   rC   r*   r+   r,   )r   r   r:   Ú_lakera_v2_callbacks       r.   Úinitialize_lakera_v2rF   =   s±   € ÝWá!2Ø×(Ñ(Ø×&Ñ&Ø —}‘}Ð%5°rÓ:Ø!×&Ñ&Ø!×,Ñ,Ø!×,Ñ,Ø×&Ñ&Ø ×*Ñ*Ø×(Ñ(Ø×(Ñ(Ø!×,Ñ,Ø)7×)XÑ)XØ'5×'TÑ'TØ .× FÑ Fô"Ðô  ×$Ñ$×9Ñ9Ð:MÔNØÐr0   c                 ó  ‡ ‡‡— ddl mŠ t        ‰ dd «      xs d}|dv }|dv }ˆˆˆ fd„}d }|r5 |«       }‰ j                  r" |dt        j
                  j                  ¬	«       |r' |dt        j
                  j                  d
¬«      }|€|}|S )Nr   )Ú_OPTIONAL_PresidioPIIMaskingÚpresidio_filter_scopeÚboth)ÚinputrJ   )ÚoutputrJ   c                  ó¼  •— t        ‰j                  dd«      ‰j                  ‰j                  ‰j                  ‰j
                  ‰j                  ‰j                  ‰j                  ‰j                  ‰j                  ‰j                  ‰j                  d¬«      }|j                  | «        ‰dd‰j                  i|¤Ž}t        j                   j#                  |«       |S )Nr   r   F)r   r   Úoutput_parse_piiÚpresidio_ad_hoc_recognizersÚmock_redacted_textr   Úpii_entities_configÚpresidio_score_thresholdsÚpresidio_analyzer_api_baseÚpresidio_anonymizer_api_baseÚpresidio_languageÚpresidio_entities_deny_listÚapply_to_outputÚ!presidio_analyze_chunk_size_bytesr&   )Údictr(   r)   rN   rO   rP   r   rQ   rR   rS   rT   rU   rV   ÚupdaterX   r*   r+   r,   )Ú	overridesÚparamsÚcallbackrH   r   r   s      €€€r.   Ú_make_presidio_callbackz4initialize_presidio.<locals>._make_presidio_callback]   sÍ   ø€ ÜØ$Ÿ=™=Ð)9¸2Ó>Ø%×*Ñ*Ø+×<Ñ<Ø(6×(RÑ(RØ-×@Ñ@Ø%×0Ñ0Ø .× BÑ BØ&4×&NÑ&NØ'5×'PÑ'PØ)7×)TÑ)TØ,×>Ñ>Ø(6×(RÑ(RØ!ô
ˆð 	�‰�iÔ ñ 7ñ 
Ø.<×.^Ñ.^ð
àñ
ˆô 	×(Ñ(×=Ñ=¸hÔGØˆr0   T)rN   r   F)rW   r   rN   )Ú1litellm.proxy.guardrails.guardrail_hooks.presidiorH   ÚgetattrrN   ÚGuardrailEventHooksÚ	post_callÚvalue)	r   r   Úfilter_scopeÚ	run_inputÚ
run_outputr^   Úprimary_callbackÚoutput_callbackrH   s	   ``      @r.   Úinitialize_presidiori   T   s©   ú€ õô " .Ð2IÈ4ÓPÒZÐTZ€LØ#Ð'8Ð8€IØ$Ð(:Ð:€Jöð4 ÐáÙ2Ó4Ðà×*Ò*Ù#Ø!%Ü.×8Ñ8×>Ñ>õñ
 Ù!8Ø Ü*×4Ñ4×:Ñ:Ø"ô"
ˆð
 Ð#Ø.ÐàÐr0   c                 ó,  — 	 ddl m}  || j                  | j                  |j                  dd«      | j                  ¬«      }t        j                  j                  |«       |S # t        $ r' t        dt        j
                  j                  z   «      ‚w xY w)Nr   )Ú_ENTERPRISE_SecretDetectionzTrying to use Secret Detectionr   r   )Údetect_secrets_configr   r   r   )Ú8litellm_enterprise.enterprise_callbacks.secret_detectionrk   ÚImportErrorÚ	Exceptionr   Úmissing_enterprise_packagerc   rl   r)   r(   r   r*   r+   r,   )r   r   rk   Ú_secret_detection_objects       r.   Úinitialize_hide_secretsrr   Ž   s“   € ðoõ	
ñ 'BØ,×BÑBØ!×&Ñ&Ø —}‘}Ð%5°rÓ:Ø!×,Ñ,ô	'Ðô ×$Ñ$×9Ñ9Ð:RÔSØ#Ð#øô ò oÜÐ8Ô;L×;gÑ;g×;mÑ;mÑmÓnÐnðoús   ‚A# Á#0Bc                 óÄ  — ddl m} d }| j                  rYg }| j                  D ]H  }t        |d«      r |j	                  |j                  «       «       Œ/|j	                  t        |«      «       ŒJ  ||j                  dd«      | j                  |t        | dd«      t        | dd	«      | j                  | j                  ¬
«      }t        j                  j                  |«       |S )Nr   )ÚToolPermissionGuardrailÚ
model_dumpr   r   Údefault_actionÚdenyÚon_disallowed_actionÚblock)r   r   Úrulesrv   rx   r   Úviolation_message_template)Ú8litellm.proxy.guardrails.guardrail_hooks.tool_permissionrt   rz   ÚhasattrÚappendru   rY   r(   r)   r`   r   r{   r*   r+   r,   )r   r   rt   rz   ÚruleÚ_tool_permission_callbacks         r.   Úinitialize_tool_permissionr�       sÏ   € õð *.€EØ×ÒØˆØ"×(Ñ(ò 	)ˆDÜ�t˜\Ô*Ø—‘˜TŸ_™_Ó.Õ/à—‘œT $›ZÕ(ð		)ñ (?Ø —}‘}Ð%5°rÓ:Ø!×&Ñ&ØÜ˜~Ð/?ÀÓHÜ$ ^Ð5KÈWÓUØ!×,Ñ,Ø#1×#LÑ#Lô(Ðô ×$Ñ$×9Ñ9Ð:SÔTØ$Ð$r0   c           
      ó  — ddl m}  ||j                  dd«      | j                  | j                  | j
                  | j                  | j                  | j                  | j                  ¬«      }t        j                  j                  |«       |S )Nr   )ÚLassoGuardrailr   r   )r   Úlasso_api_keyr3   Úuser_idÚconversation_idÚmaskr   r   )Ú.litellm.proxy.guardrails.guardrail_hooks.lassorƒ   r(   r4   r3   Úlasso_user_idÚlasso_conversation_idr‡   r)   r   r*   r+   r,   )r   r   rƒ   Ú_lasso_callbacks       r.   Úinitialize_lassorŒ   »   s|   € õ Ná+Ø —}‘}Ð%5°rÓ:Ø$×,Ñ,Ø×(Ñ(Ø×,Ñ,Ø&×<Ñ<Ø× Ñ Ø!×&Ñ&Ø!×,Ñ,ô	€Oô ×$Ñ$×9Ñ9¸/ÔJàÐr0   c                 ó  — ddl m} | j                  st        d«      ‚| j                  st        d«      ‚ ||j                  dd«      | j                  | j                  xs d| j                  | j                  t        | dd	«      t        | d
d	«      t        | dd	«      t        | dd «      t        | dd«      t        | dd «      �t        t        | dd «      «      nd| j                  ¬«      }t        j                  j                  |«       |S )Nr   )ÚPanwPrismaAirsHandlerz%PANW Prisma AIRS: api_key is requiredz*PANW Prisma AIRS: profile_name is requiredr   Úpanw_prisma_airszHhttps://service.api.aisecurity.paloaltonetworks.com/v1/scan/sync/requestÚmask_on_blockFr   r   Úapp_nameÚfallback_on_errorry   Útimeoutg      $@)r   r4   r3   Úprofile_namer   r�   r   r   r‘   r’   r“   r{   )Ú9litellm.proxy.guardrails.guardrail_hooks.panw_prisma_airsrŽ   r4   Ú
ValueErrorr”   r(   r3   r   r`   Úfloatr{   r*   r+   r,   )r   r   rŽ   Ú_panw_callbacks       r.   Úinitialize_panw_prisma_airsr™   Ð   s  € õð ×!Ò!ÜÐ@ÓAÐAØ×&Ò&ÜÐEÓFÐFá1Ø —}‘}Ð%5Ð7IÓJØ×&Ñ&Ø×(Ñ(ÒvÐ,vØ#×0Ñ0Ø!×,Ñ,Ü˜n¨o¸uÓEÜ$ ^Ð5KÈUÓSÜ% nÐ6MÈuÓUÜ˜¨°TÓ:Ü! .Ð2EÀwÓOô �~ y°$Ó7ÐCô ”'˜.¨)°TÓ:Ô;àà#1×#LÑ#Lô)€Nô, ×$Ñ$×9Ñ9¸.ÔIàÐr0   )Útypingr   r   r*   Úlitellm.proxy._typesr   Úlitellm.types.guardrailsÚLitellmParamsÚ	Guardrailr/   r8   rF   ri   rr   r�   rŒ   r™   r&   r0   r.   ú<module>rŸ      sŸ   ðç ã Ý 2Ü &ð" }ð "Àó "ðJ mð À	ó ð¨ð À9ó ð.7¨ð 7À)ó 7ðt$¨Mð $Àió $ð$%¨}ð %Èó %ð6Ø!ðàóó*"r0   