Skip to content

fix: categorize provider unsupported-MIME rejection as User#943

Open
cotovanu-cristian wants to merge 1 commit into
mainfrom
fix/categorize-unsupported-mime-as-user
Open

fix: categorize provider unsupported-MIME rejection as User#943
cotovanu-cristian wants to merge 1 commit into
mainfrom
fix/categorize-unsupported-mime-as-user

Conversation

@cotovanu-cristian

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

Copy link
Copy Markdown
Collaborator

Problem

A file attachment whose MIME type the model provider cannot read (e.g. application/octet-stream to Bedrock Converse) caused the run to fail with an opaque Unknown category. The underlying ValueError("Unsupported MIME type: ...") is raised by langchain_aws during Converse request conversion.

Approach

Format support for non-image attachments is delegated to the LLM/provider (per #842, which deliberately removed the client-side file-type restriction). This PR does not reintroduce a MIME allow-list. Instead it reacts to the provider's actual verdict:

  • multimodal/invoke.pybuild_file_content_blocks_for keeps the feat: remove file type restriction for analyze files tool #842 pass-through (any non-image MIME → generic file block; no gating).
  • exceptions/attachments.pyraise_for_unsupported_attachment(exc) walks the exception's __cause__/__context__ chain for the provider's "Unsupported MIME type" marker and, if present, raises a User-categorized AgentRuntimeError(FILE_ERROR) with an actionable message. No-op otherwise.
  • react/llm_node.py — calls it in the model.ainvoke except block (the model-invocation boundary), before the generic provider-HTTP handling.

So we translate the provider's decision into a clean User error at the boundary, rather than pre-empting it with our own list.

Tests

  • test_exception_helpers.py — direct + cause-chain + no-op cases for raise_for_unsupported_attachment.
  • test_utils.py — restored feat: remove file type restriction for analyze files tool #842 expectations: octet-stream and empty MIME pass through as file blocks (no raise at the source).
  • Full tests/agent suite: 920 passed; ruff + mypy clean.

Sanitized: synthetic repros only; no internal/ticket/customer references.

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

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 improves agent-runtime error categorization by converting “unsupported attachment MIME type” failures (raised locally during provider request conversion) into structured AgentRuntimeErrors categorized as USER (AGENT_RUNTIME.FILE_ERROR) at the LLM invocation boundary.

Changes:

  • Add raise_for_unsupported_attachment helper to detect ValueError messages containing Unsupported MIME type: in an exception __cause__ chain and re-raise as a USER FILE_ERROR.
  • Invoke the new helper from the create_llm_node exception handling path alongside existing provider HTTP error mapping.
  • Add a test asserting the unsupported-MIME conversion failure is categorized as USER with code AGENT_RUNTIME.FILE_ERROR.

Reviewed changes

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

File Description
tests/agent/react/test_llm_node.py Adds regression test asserting unsupported MIME type errors are mapped to USER / FILE_ERROR.
src/uipath_langchain/agent/react/llm_node.py Hooks unsupported-attachment detection into the LLM invocation except block.
src/uipath_langchain/agent/exceptions/attachments.py Introduces helper that detects “Unsupported MIME type” conversion failures and raises a structured AgentRuntimeError.

Comment on lines +35 to +45
if isinstance(cause, ValueError) and _UNSUPPORTED_MIME_MARKER in str(cause):
raise AgentRuntimeError(
code=AgentRuntimeErrorCode.FILE_ERROR,
title="Unsupported file attachment format.",
detail=(
"An attachment has a file type the model does not support. "
"Remove the attachment or convert it to a supported format."
),
category=UiPathErrorCategory.USER,
) from e
cause = cause.__cause__
Comment thread tests/agent/react/test_llm_node.py Outdated
Comment on lines +372 to +377
self.mock_model.ainvoke = AsyncMock(
side_effect=ValueError(
"Unsupported MIME type: application/octet-stream."
" Please refer to the provider documentation for supported formats."
)
)
@cotovanu-cristian cotovanu-cristian force-pushed the fix/categorize-unsupported-mime-as-user branch from 58847d5 to 7b7e339 Compare June 25, 2026 20:44
Format support for non-image attachments is delegated to the LLM/provider
(#842) — do not reintroduce a client-side MIME allow-list. Instead, translate
the provider's own 'Unsupported MIME type' ValueError (raised by langchain_aws
Bedrock Converse during request conversion) into a User-categorized
AgentRuntimeError(FILE_ERROR) at the model-invocation boundary in llm_node,
matched across the exception chain. build_file_content_blocks_for keeps the
#842 pass-through behavior (any non-image MIME -> file block).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cotovanu-cristian cotovanu-cristian force-pushed the fix/categorize-unsupported-mime-as-user branch from 7b7e339 to 11ceff9 Compare June 26, 2026 11:11
@cotovanu-cristian cotovanu-cristian changed the title fix(errors): categorize unsupported attachment MIME type as User fix: categorize provider unsupported-MIME rejection as User Jun 26, 2026
@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