Skip to content

fix(agent): fail loud on non-UUID attachment output id as System error#941

Open
cotovanu-cristian wants to merge 1 commit into
mainfrom
fix/guard-attachment-output-non-uuid-id
Open

fix(agent): fail loud on non-UUID attachment output id as System error#941
cotovanu-cristian wants to merge 1 commit into
mainfrom
fix/guard-attachment-output-non-uuid-id

Conversation

@cotovanu-cristian

@cotovanu-cristian cotovanu-cristian commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Problem

get_job_attachments in agent/react/job_attachments.py validated every
extracted tool-output attachment with Attachment.model_validate(...) inside
a loop with no error handling. Attachment.id is typed uuid.UUID, so when a
tool returned an attachment whose ID was not a valid UUID (e.g. "att_x"),
pydantic raised an uncaught ValidationError that propagated out and crashed
the entire agent run.

Fix

A tool returning an attachment with a non-UUID id is unrecoverable invalid data
the SDK cannot safely proceed with, so this is now a fail-loud System error,
not a skip. get_job_attachments raises an AgentRuntimeError with code
INVALID_ATTACHMENT_ID and category UiPathErrorCategory.SYSTEM (matching the
existing pattern in analyze_files_tool.py).

The output path deliberately does not mirror the input-side skip in
replace_job_attachment_ids: silently dropping invalid tool output would hide a
correctness problem, so it must surface as a System failure. The error detail
names the offending id and nothing else, so no other attachment data leaks.

Test

Replaced the prior skip-assertion test with
TestGetJobAttachments::test_raises_system_error_on_non_uuid_attachment_id,
which feeds a tool-output payload containing an attachment with a non-UUID id
("att_x") and asserts get_job_attachments raises an AgentRuntimeError
categorized SYSTEM with code INVALID_ATTACHMENT_ID and the offending id in
the detail. Confirmed failing-test-first (fails against the old skip behavior,
passes with the raise). Full local checks (ruff format, ruff check, mypy,
pytest) pass.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings June 25, 2026 16:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the ReAct agent’s job-attachment extraction so malformed tool-output attachments (notably those with non-UUID ID values) no longer crash an agent run, and adds a regression test to ensure invalid attachments are skipped while valid ones are retained.

Changes:

  • Update get_job_attachments to catch pydantic.ValidationError per extracted attachment and skip invalid entries instead of raising.
  • Extend the function docstring to document the “skip invalid attachments” behavior.
  • Add a test ensuring a non-UUID attachment ID in tool output is ignored and does not raise.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/uipath_langchain/agent/react/job_attachments.py Wraps per-attachment validation in try/except ValidationError so malformed attachments don’t abort the run.
tests/agent/react/test_job_attachments.py Adds coverage verifying non-UUID attachment IDs are skipped and valid attachments still return.

@cotovanu-cristian cotovanu-cristian force-pushed the fix/guard-attachment-output-non-uuid-id branch from 532f47e to 0323cb0 Compare June 25, 2026 20:37
@cotovanu-cristian cotovanu-cristian changed the title fix(errors): categorize non-UUID attachment output as System (skip invalid attachment IDs) fix(agent): fail loud on non-UUID attachment output id as System error Jun 25, 2026
@cotovanu-cristian cotovanu-cristian force-pushed the fix/guard-attachment-output-non-uuid-id branch from 0323cb0 to 046a6f4 Compare June 26, 2026 09:52
When a tool returned a job attachment whose ID is not a valid UUID, the
loop in get_job_attachments called Attachment.model_validate with no error
handling, so pydantic raised an uncaught ValidationError that crashed the
agent run.

An attachment with a non-UUID id is unrecoverable invalid data the SDK
cannot safely proceed with, so it is now raised as a System-categorized
AgentRuntimeError (INVALID_ATTACHMENT_ID) rather than swallowed. The output
path deliberately does NOT mirror the input-side skip in
replace_job_attachment_ids: invalid tool output must surface as a System
failure, not be silently dropped. The error detail names the offending id
without leaking any other attachment data.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cotovanu-cristian cotovanu-cristian force-pushed the fix/guard-attachment-output-non-uuid-id branch from 046a6f4 to 04f5f64 Compare June 26, 2026 10:56
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants