Skip to content

fix: keep the response body out of UiPathAPIError.__str__ [PC-5002] - #135

Merged
ionut-mihalache-uipath merged 1 commit into
mainfrom
fix/pc-5002-api-error-str-omits-body
Sep 9, 2026
Merged

fix: keep the response body out of UiPathAPIError.__str__ [PC-5002]#135
ionut-mihalache-uipath merged 1 commit into
mainfrom
fix/pc-5002-api-error-str-omits-body

Conversation

@ionut-mihalache-uipath

Copy link
Copy Markdown
Collaborator

What changed

UiPathAPIError.__str__ no longer appends self.body.

The traceback module renders the final exception line with str(). That meant the relayed provider response body was copied verbatim into every printed stacktrace — including the one shipped as AgentRun.Failed.ErrorTraceback — regardless of what the consuming runtime chose to put in its own customer-facing error. The body is content of unknown sensitivity and may carry PII.

The body stays on the .body attribute, unchanged, for callers that classify on it. __repr__ is unchanged.

Before:

UiPathBadRequestError: Bad Request (Status Code: 400) {'error': {'message': '<provider body>'}}

After:

UiPathBadRequestError: Bad Request (Status Code: 400)

Why

The body is not something the runtime can reason about before it reaches a customer-visible traceback, so it should not be part of the serialized form of the exception at all.

Packages affected

Both — core and langchain version together per the repo's lockstep rule.

  • core 1.18.01.18.5
  • langchain 1.18.41.18.5, with its uipath-llm-client floor raised to >=1.18.5
  • changelog entries added to both

Tests

Three tests added in tests/core/features/test_exceptions.py:

  • test_str_omits_the_response_body (parametrized over a JSON and a text body) — asserts the body content is absent and pins the exact new format
  • test_str_omission_does_not_drop_the_body_attribute — guards that .body still carries the payload for callers that classify on it

Red-green verified: both test_str_omits_the_response_body cases fail against the old __str__ and pass with the fix.

Verification

  • ruff check — all checks passed
  • ruff format . — 165 files unchanged
  • pyright — 0 errors, 0 warnings
  • pytest tests — 650 passed, 35 skipped, 9 xfailed (up from 647 on main)

The 2507 fixture errors in the local run are pre-existing and identical on a clean tree — tests/conftest.py:85 builds LLMGatewaySettings(), which needs LLMGW_URL/LLMGW_SEMANTIC_* env vars that aren't set locally. CI supplies them.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BnGx1AgzrA4Qq1bRrbvjyd

The traceback module renders the final exception line with str(), so the
relayed provider response body was copied verbatim into every printed
stacktrace -- including the one shipped as AgentRun.Failed.ErrorTraceback --
regardless of what the consuming runtime chose to put in its own
customer-facing error. The body is content of unknown sensitivity and may
carry PII.

The body now stays on the `body` attribute, unchanged, for callers that
classify on it, and out of the serialized form. `__repr__` is unchanged.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BnGx1AgzrA4Qq1bRrbvjyd
# ``self.body`` is deliberately absent. The traceback module renders the
# final exception line with str(), so anything here is copied verbatim
# into every printed stacktrace -- potentially including PII
return f"{self.__class__.__name__}: {self.message} (Status Code: {self.status_code})"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is removing the whole body a valid solution to this PII vs traceability trade off? excluding the whole body might be removing too much info that would be helpful when debugging. maybe it might be better to try to isolate potential PII on specific body fields and exclude those. for instance for bad request we had this discussion so it might be nice to map out exactly on what fields PII bad request can appear (https://uipath-product.slack.com/archives/C05AANXHV9S/p1788178862719219)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

given we don't know for sure which fields can contain PII then it's safer to ignore all of them.

@ionut-mihalache-uipath
ionut-mihalache-uipath merged commit d188045 into main Sep 9, 2026
17 checks passed
@ionut-mihalache-uipath
ionut-mihalache-uipath deleted the fix/pc-5002-api-error-str-omits-body branch September 9, 2026 10:47
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