Skip to content

Commit b0625ac

Browse files
committed
CM-58331-send error if available
1 parent 1789349 commit b0625ac

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

cycode/cli/apps/ai_guardrails/scan/handlers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ def handle_before_submit_prompt(ctx: typer.Context, payload: AIHookPayload, poli
5555
scan_id = None
5656
block_reason = None
5757
outcome = AIHookOutcome.ALLOWED
58+
error_message = None
5859

5960
try:
6061
violation_summary, scan_id = _scan_text_for_secrets(ctx, clipped, timeout_ms)
@@ -72,6 +73,7 @@ def handle_before_submit_prompt(ctx: typer.Context, payload: AIHookPayload, poli
7273
AIHookOutcome.ALLOWED if get_policy_value(policy, 'fail_open', default=True) else AIHookOutcome.BLOCKED
7374
)
7475
block_reason = BlockReason.SCAN_FAILURE
76+
error_message = str(e)
7577
raise e
7678
finally:
7779
ai_client.create_event(
@@ -80,6 +82,7 @@ def handle_before_submit_prompt(ctx: typer.Context, payload: AIHookPayload, poli
8082
outcome,
8183
scan_id=scan_id,
8284
block_reason=block_reason,
85+
error_message=error_message,
8386
)
8487

8588

@@ -107,6 +110,7 @@ def handle_before_read_file(ctx: typer.Context, payload: AIHookPayload, policy:
107110
scan_id = None
108111
block_reason = None
109112
outcome = AIHookOutcome.ALLOWED
113+
error_message = None
110114

111115
try:
112116
# Check path-based denylist first
@@ -154,6 +158,7 @@ def handle_before_read_file(ctx: typer.Context, payload: AIHookPayload, policy:
154158
AIHookOutcome.ALLOWED if get_policy_value(policy, 'fail_open', default=True) else AIHookOutcome.BLOCKED
155159
)
156160
block_reason = BlockReason.SCAN_FAILURE
161+
error_message = str(e)
157162
raise e
158163
finally:
159164
ai_client.create_event(
@@ -162,6 +167,7 @@ def handle_before_read_file(ctx: typer.Context, payload: AIHookPayload, policy:
162167
outcome,
163168
scan_id=scan_id,
164169
block_reason=block_reason,
170+
error_message=error_message,
165171
)
166172

167173

@@ -195,6 +201,7 @@ def handle_before_mcp_execution(ctx: typer.Context, payload: AIHookPayload, poli
195201
scan_id = None
196202
block_reason = None
197203
outcome = AIHookOutcome.ALLOWED
204+
error_message = None
198205

199206
try:
200207
if get_policy_value(mcp_config, 'scan_arguments', default=True):
@@ -220,6 +227,7 @@ def handle_before_mcp_execution(ctx: typer.Context, payload: AIHookPayload, poli
220227
AIHookOutcome.ALLOWED if get_policy_value(policy, 'fail_open', default=True) else AIHookOutcome.BLOCKED
221228
)
222229
block_reason = BlockReason.SCAN_FAILURE
230+
error_message = str(e)
223231
raise e
224232
finally:
225233
ai_client.create_event(
@@ -228,6 +236,7 @@ def handle_before_mcp_execution(ctx: typer.Context, payload: AIHookPayload, poli
228236
outcome,
229237
scan_id=scan_id,
230238
block_reason=block_reason,
239+
error_message=error_message,
231240
)
232241

233242

cycode/cyclient/ai_security_manager_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def create_event(
6161
outcome: 'AIHookOutcome',
6262
scan_id: Optional[str] = None,
6363
block_reason: Optional['BlockReason'] = None,
64+
error_message: Optional[str] = None,
6465
) -> None:
6566
"""Create an AI hook event from hook payload."""
6667
conversation_id = payload.conversation_id
@@ -77,6 +78,7 @@ def create_event(
7778
'cli_scan_id': scan_id,
7879
'mcp_server_name': payload.mcp_server_name,
7980
'mcp_tool_name': payload.mcp_tool_name,
81+
'error_message': error_message,
8082
}
8183

8284
try:

0 commit comments

Comments
 (0)