Skip to content

Commit aa196f0

Browse files
update dash app
1 parent 2b6721f commit aa196f0

File tree

1 file changed

+73
-21
lines changed
  • trusted-ai/runtime-evaluations/real-time-guardrails

1 file changed

+73
-21
lines changed

trusted-ai/runtime-evaluations/real-time-guardrails/app.py

Lines changed: 73 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -746,8 +746,12 @@ def handle_evaluation(
746746
# For safety metrics: high score = high risk (score >= threshold)
747747
if metric_category == "rag":
748748
is_high_risk = score_value < threshold_for_metric
749+
# RAG: Block/Pass Output
750+
guardrail_action = "Block Output" if is_high_risk else "Pass Output"
749751
else:
750752
is_high_risk = score_value >= threshold_for_metric
753+
# Safety: Block/Pass Input
754+
guardrail_action = "Block Input" if is_high_risk else "Pass Input"
751755

752756
metric_threshold_map[metric_display_name] = threshold_for_metric
753757
results_list.append(
@@ -757,7 +761,7 @@ def handle_evaluation(
757761
"Threshold": threshold_for_metric,
758762
"Category": metric_category,
759763
"Risk Level": "High" if is_high_risk else "Low",
760-
"Guardrail Action": "block" if is_high_risk else "pass",
764+
"Guardrail Action": guardrail_action,
761765
}
762766
)
763767

@@ -767,6 +771,13 @@ def handle_evaluation(
767771
high_risk_count = len(
768772
[r for r in results_list if r["Risk Level"] == "High"]
769773
)
774+
# Calculate separate counts for input (safety) and output (RAG) high risk
775+
high_risk_input_count = len(
776+
[r for r in results_list if r["Risk Level"] == "High" and r["Category"] == "safety"]
777+
)
778+
high_risk_output_count = len(
779+
[r for r in results_list if r["Risk Level"] == "High" and r["Category"] == "rag"]
780+
)
770781
max_score = max([r["Score"] for r in results_list]) if results_list else 0
771782
avg_score = (
772783
sum([r["Score"] for r in results_list]) / len(results_list)
@@ -916,7 +927,7 @@ def handle_evaluation(
916927
},
917928
{
918929
"if": {
919-
"filter_query": '{Guardrail Action} = "block"',
930+
"filter_query": '{Guardrail Action} contains "Block"',
920931
"column_id": "Guardrail Action",
921932
},
922933
"backgroundColor": "#ffebee",
@@ -925,7 +936,7 @@ def handle_evaluation(
925936
},
926937
{
927938
"if": {
928-
"filter_query": '{Guardrail Action} = "pass"',
939+
"filter_query": '{Guardrail Action} contains "Pass"',
929940
"column_id": "Guardrail Action",
930941
},
931942
"backgroundColor": "#e8f5e8",
@@ -951,29 +962,70 @@ def handle_evaluation(
951962
dbc.Row(
952963
[
953964
dbc.Col(
954-
html.H6(
955-
"Overall Guardrail Action:", className="mb-0"
956-
),
957-
width="auto",
965+
[
966+
dbc.Row(
967+
[
968+
dbc.Col(
969+
html.H6(
970+
"Overall Input Action:", className="mb-0"
971+
),
972+
width="auto",
973+
),
974+
dbc.Col(
975+
dbc.Badge(
976+
"PASS" if high_risk_input_count == 0 else "BLOCK",
977+
color=(
978+
"success"
979+
if high_risk_input_count == 0
980+
else "danger"
981+
),
982+
className="ms-2",
983+
style={
984+
"fontSize": "1rem",
985+
"padding": "0.5rem 1rem",
986+
},
987+
),
988+
width="auto",
989+
),
990+
],
991+
align="center",
992+
),
993+
],
994+
width=6,
958995
),
959996
dbc.Col(
960-
dbc.Badge(
961-
"PASS" if high_risk_count == 0 else "BLOCK",
962-
color=(
963-
"success"
964-
if high_risk_count == 0
965-
else "danger"
997+
[
998+
dbc.Row(
999+
[
1000+
dbc.Col(
1001+
html.H6(
1002+
"Overall Output Action:", className="mb-0"
1003+
),
1004+
width="auto",
1005+
),
1006+
dbc.Col(
1007+
dbc.Badge(
1008+
"PASS" if high_risk_output_count == 0 else "BLOCK",
1009+
color=(
1010+
"success"
1011+
if high_risk_output_count == 0
1012+
else "danger"
1013+
),
1014+
className="ms-2",
1015+
style={
1016+
"fontSize": "1rem",
1017+
"padding": "0.5rem 1rem",
1018+
},
1019+
),
1020+
width="auto",
1021+
),
1022+
],
1023+
align="center",
9661024
),
967-
className="ms-2",
968-
style={
969-
"fontSize": "1rem",
970-
"padding": "0.5rem 1rem",
971-
},
972-
),
973-
width="auto",
1025+
],
1026+
width=6,
9741027
),
9751028
],
976-
align="center",
9771029
),
9781030
]
9791031
),

0 commit comments

Comments
 (0)