Repository navigation
fix(py/agents): redact agent exception text on the wire - #41
Merged
Merged
Conversation
huangjeff5
force-pushed
the
fix/py-custom-agent-redact-errors
branch
from
November 9, 2026 19:07
53b8846 to
1f6b023
Compare
SessionRunner is exported from genkit.exp.agent, so a public agent_name attribute shows up on every custom agent's runner. It only feeds the redaction log line.
Recording 'internal error' in to_error_details lost the text for in-process callers, the store, and the Dev UI, and still let any non-public GenkitError (NOT_FOUND, provider_error 429) reach HTTP callers verbatim. Move redaction to genkit.web, where every adapter frames results: result_json and to_sse pass a failed AgentOutput/SessionSnapshot error through client_safe_failure. A PublicError's Failure is marked (private, unserialized flag, like Go's status.Error.Public) and goes out as is; anything else keeps its status with a generic message and no details. Same rule as error_body for flows and Go's clientSafeError. to_error_details keeps the exception text again, matching JS and Go, so customAgentFailing goes back to a plain RuntimeError and the shared agent.yaml case runs on real behavior. The server-side log with traceback stays for causes generate's rule would hide.
Pydantic's frozen=True guards fields only; private attrs are stored apart and settable. Pyrefly reads _public as a frozen field.
huangjeff5
force-pushed
the
fix/py-custom-agent-redact-errors
branch
from
November 10, 2026 22:14
9df9fdc to
a6e6b21
Compare
…quality on Failure
pavelgj
approved these changes
Nov 11, 2026
…redact stored snapshots
…edact-errors # Conflicts: # packages/genkit/src/genkit/_ai/_generate.py
…ng Go Go's wire.ClientMessage returns err.Error() when GENKIT_ENV=dev, for both a served agent's failed turn (clientSafeError) and a served flow (clientError). client_safe_failure and error_body now do the same. Status and HTTP code are unchanged, so error_status still pairs with error_body.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A served agent whose turn raised sent the raw exception text to the HTTP caller. A failed turn goes out as a normal
200result, soerror_body, which redacts errors for served flows, never saw it.genkit.webnow applies the same rule to a failed turn'serror: only aPublicError's message leaves the process.Main Changes
result_jsonandto_ssepassAgentOutput.errorandSessionSnapshot.errorthroughclient_safe_failure.statusstays so clients can branch on it; a non-public message becomes generic status text (Internal Error,Not Found, ...) anddetailsis dropped. FastAPI, Flask, Django,getSnapshot, and customto_sseroutes all frame throughgenkit.web. In-process callers (chat().send()), session stores, and the Dev UI keep the real text. Caller-facing snapshot and resume errors (SNAPSHOT_NOT_FOUND,SNAPSHOT_NOT_RESUMABLE,INVALID_RESUME,UNRESOLVED_TOOL_REQUEST, and snapshot lookup selector errors) now raisePublicError(..., reason=...)(matching Go'sstatus.PublicErrorf), andPublicErrorgains a keyword-onlyreason: ErrorReason | None = Noneparameter.PublicErrorprovenance rides onFailurewithout changing equality: When a turn raisesPublicError,to_error_detailsandgenerateset a private, non-serialized flag onFailure(stripping anystackkey indetailsbefore the wire).InMemorySessionStoredrops privateFailureprovenance on copy so stored snapshot errors are redacted on HTTPgetSnapshotconsistently with JSON-backed stores (FileSessionStore,FirestoreSessionStore) and Go'scopySnapshot.Failure.__eq__comparesself.__dict__ == other.__dict__, ignoring private attributes.PublicErrorturn failure (except an escapedInterrupt) logs oneERRORline with its traceback andagent=<name>so the server log retains what the HTTP wire redacts, skipping failuresgeneratealready logged for a crashing tool or model.Breaking changes
PublicErrorfailure text anddetailson HTTP (statusis kept); caller-facing snapshot/resume errors (SNAPSHOT_NOT_FOUND,SNAPSHOT_NOT_RESUMABLE,INVALID_RESUME,UNRESOLVED_TOOL_REQUEST) stay readable asPublicErrorwithdetails.reason;PublicErrorgains a keyword-onlyreason=parameter; stored snapshot errors are always redacted on HTTPgetSnapshotacross all session stores.Cross-SDK
On the HTTP agent wire (
POST /<agent>,?stream=true, andgetSnapshot), non-public failures dropdetailsand replacemessagewith a generic status label:convertKeepText), marks caller-facing snapshot/resume errors withstatus.PublicErrorf, and redacts non-public and stored snapshot errors on the wire (clientSafeError,status.Error.Public).AgentOutputandSessionSnapshotkeep their shape. JStoErrorDetailsstill sendserr.messageunredacted on served agent responses.