mirror of
https://github.com/hoshikawa2/nemo_guardrails_configuration.git
synced 2026-07-09 17:04:20 +00:00
Ajuste segurança-extra
This commit is contained in:
@@ -18,7 +18,11 @@ from src.actions import (
|
||||
detectar_loop_action,
|
||||
medir_tamanho_mensagem_action,
|
||||
calcular_precisao_revocacao_action,
|
||||
avaliar_acuracia_semantica_action
|
||||
avaliar_acuracia_semantica_action,
|
||||
detectar_prompt_injection_jailbreak_action,
|
||||
detectar_rag_injection_context_poisoning_action,
|
||||
detectar_data_leakage_input_action,
|
||||
detectar_data_leakage_output_action
|
||||
)
|
||||
def init(app: LLMRails):
|
||||
|
||||
@@ -41,3 +45,7 @@ def init(app: LLMRails):
|
||||
app.register_action(medir_tamanho_mensagem_action)
|
||||
app.register_action(calcular_precisao_revocacao_action)
|
||||
app.register_action(avaliar_acuracia_semantica_action)
|
||||
app.register_action(detectar_prompt_injection_jailbreak_action)
|
||||
app.register_action(detectar_rag_injection_context_poisoning_action)
|
||||
app.register_action(detectar_data_leakage_input_action)
|
||||
app.register_action(detectar_data_leakage_output_action)
|
||||
@@ -1,21 +1,21 @@
|
||||
models:
|
||||
- type: main
|
||||
engine: openai
|
||||
model: gpt-5
|
||||
model: openai.gpt-4.1
|
||||
api_key_env_var: OPENAI_API_KEY
|
||||
parameters:
|
||||
temperature: 0
|
||||
base_url: http://127.0.0.1:8051/v1
|
||||
base_url: https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/v1
|
||||
max_tokens: 50 # 🔥 evita respostas longas do LLM
|
||||
|
||||
# 🔥 usado apenas se você chamar explicitamente no flow
|
||||
- type: self_check_input
|
||||
engine: openai
|
||||
model: openai.gpt-oss-120b
|
||||
model: openai.gpt-4.1
|
||||
api_key_env_var: OPENAI_API_KEY
|
||||
parameters:
|
||||
temperature: 0
|
||||
base_url: http://127.0.0.1:8051/v1
|
||||
base_url: https://inference.generativeai.us-chicago-1.oci.oraclecloud.com/20231130/actions/v1
|
||||
|
||||
|
||||
rails:
|
||||
|
||||
@@ -22,3 +22,17 @@ guardrails:
|
||||
- {codigo: VCTN, item: "Tom de Voz", mecanismo: llm_judge}
|
||||
- {codigo: REVPREC_METRIC, item: "Precisão e Revocação", mecanismo: python}
|
||||
- {codigo: SEMAC, item: "Acurácia Semântica STT", mecanismo: python}
|
||||
# =========================
|
||||
# SEGURANÇA - INPUT
|
||||
# =========================
|
||||
|
||||
- {codigo: PINJ, item: "Prompt Injection / Jailbreak Defense", mecanismo: llm_rail}
|
||||
- {codigo: RAGSEC, item: "RAG Injection / Context Poisoning", mecanismo: llm_rail}
|
||||
- {codigo: DLEX_IN, item: "Data Leakage / Secret Exfiltration (Input)", mecanismo: llm_rail}
|
||||
|
||||
# =========================
|
||||
# SEGURANÇA - OUTPUT
|
||||
# =========================
|
||||
|
||||
- {codigo: DLEX_OUT, item: "Data Leakage / Secret Exfiltration (Output)", mecanismo: Regex + llm_rail}
|
||||
- {codigo: SAFE_OUT, item: "Content Safety / Unsafe Output", mecanismo: llm_rail}
|
||||
|
||||
@@ -9,7 +9,7 @@ define flow check_input_terms
|
||||
$ok_oos = execute detectar_out_of_scope_action
|
||||
|
||||
# 💰 Regras de negócio
|
||||
$ok_adj = execute validar_alcada_action
|
||||
$ok_adj = execute validar_alcada_action(ajuste_valor=$ajuste_valor,limite=$limite)
|
||||
|
||||
# 🧠 Contexto
|
||||
$ok_hist = execute validar_consistencia_historica_action
|
||||
@@ -19,8 +19,13 @@ define flow check_input_terms
|
||||
$ok_size = execute medir_tamanho_mensagem_action
|
||||
$ok_fbk = execute detectar_fallback_action
|
||||
|
||||
# Segurança - Adicional
|
||||
$ok_pinj = execute detectar_prompt_injection_jailbreak_action
|
||||
$ok_ragsec = execute detectar_rag_injection_context_poisoning_action
|
||||
$ok_dlex_in = execute detectar_data_leakage_input_action
|
||||
|
||||
# 🚨 HARD BLOCK
|
||||
if not ($ok_msk and $ok_tox and $ok_oos and $ok_adj and $ok_hist)
|
||||
if not ($ok_msk and $ok_tox and $ok_oos and $ok_adj and $ok_hist and $ok_pinj and $ok_ragsec and $ok_dlex_in)
|
||||
bot refuse to respond
|
||||
stop
|
||||
|
||||
|
||||
@@ -6,21 +6,24 @@ define flow check_output_terms
|
||||
$ok_sup = execute supervisor_vas_avulso_action
|
||||
|
||||
# 📡 Compliance
|
||||
$ok_cmp = execute enforce_compliance_anatel_action
|
||||
$ok_cmp = execute enforce_compliance_anatel_action(requer_protocolo=$requer_protocolo)
|
||||
|
||||
# 📊 Métricas
|
||||
$ok_tcr = execute calcular_tcr_action
|
||||
$ok_tok = execute contabilizar_tokens_action
|
||||
$ok_efic = execute calcular_eficiencia_nlu_action
|
||||
$ok_nom = execute detectar_no_match_rag_action
|
||||
#$ok_nom = execute detectar_no_match_rag_action
|
||||
$ok_prec = execute calcular_precisao_revocacao_action
|
||||
$ok_sem = execute avaliar_acuracia_semantica_action
|
||||
|
||||
# Segurança - Extra
|
||||
$ok_delex_out = execute detectar_data_leakage_output_action
|
||||
|
||||
# 🚨 Auditoria
|
||||
$ok_viol = execute registrar_violacao_action
|
||||
|
||||
# 🚨 HARD BLOCK (só qualidade crítica)
|
||||
if not ($ok_revp and $ok_gnd and $ok_sup and $ok_cmp)
|
||||
if not ($ok_cmp)
|
||||
bot refuse to respond
|
||||
stop
|
||||
|
||||
|
||||
Reference in New Issue
Block a user