Repository navigation
Python: fix(embeddings): wrap undecodable base64 payloads in a framework error - #9705
Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit intoOct 29, 2026
Conversation
lisry-1
temporarily deployed
to
github-app-auth
October 26, 2026 12:48 — with
GitHub Actions
Inactive
lisry-1
temporarily deployed
to
github-app-auth
October 26, 2026 12:49 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Non-ASCII payloads still escape both handlers as unannotated ValueError exceptions, and Foundry’s decode-error handler lacks regression coverage.
2 open issues
What changed in this PR
This PR addresses #9511 by giving malformed base64 embedding responses contextual framework errors in the Python OpenAI and Foundry integrations.
Changes:
- Wraps base64 decoding errors in
IntegrationInvalidResponseException. - Rejects decoded lengths that are not divisible by four, reporting the input index and byte count.
- Adds regression tests for malformed payloads.
| File | Description |
|---|---|
python/packages/openai/tests/openai/test_openai_embedding_client.py |
Tests invalid decoded lengths and undecodable payloads. |
python/packages/openai/agent_framework_openai/_embedding_client.py |
Adds contextual errors around base64 decoding and length validation. |
python/packages/foundry/tests/foundry/test_foundry_embedding_client.py |
Tests invalid decoded lengths in project mode. |
python/packages/foundry/agent_framework_foundry/_embedding_client.py |
Adds equivalent validation using original input indices. |
Review effort: Balanced
lisry-1
temporarily deployed
to
github-app-auth
October 26, 2026 13:17 — with
GitHub Actions
Inactive
…ork error
With `encoding_format="base64"`, both embedding clients call
`base64.b64decode` on each payload before unpacking it as little-endian
float32 values. A payload that cannot be decoded at all (bad padding or
alphabet, or non-ASCII input that `str.encode('ascii')` rejects) escapes as
a bare `binascii.Error` / `UnicodeEncodeError`, with no reference to the
input that broke, so a malformed response is indistinguishable from a bug
in the client.
Both `binascii.Error` and `UnicodeEncodeError` are `ValueError` subclasses,
so the decode is wrapped in `except ValueError` and re-raised as
`IntegrationInvalidResponseException`, naming the input index and preserving
the original cause.
`microsoft#9512` already reports a *misaligned* payload (decoded length not a multiple
of 4) for the OpenAI client, so this change intentionally only adds the
missing undecodable-payload path there; the Foundry client had neither guard,
so it gains both.
Regression tests cover an undecodable payload and a non-ASCII payload for
OpenAI, and a 5-byte payload and an undecodable payload for Foundry.
lisry-1
force-pushed
the
fix/openai-embedding-base64-error
branch
from
October 28, 2026 08:51
32e6c7e to
c805f65
Compare
lisry-1
temporarily deployed
to
github-app-auth
October 28, 2026 08:51 — with
GitHub Actions
Inactive
lisry-1
temporarily deployed
to
github-app-auth
October 28, 2026 08:52 — with
GitHub Actions
Inactive
Member
|
lisry-1 Thanks for clarifying the scope relative to #9512. This is an agreed follow-up to #9511: the remaining undecodable-payload handling and Foundry parity are in scope. |
Eduard van Valkenburg (eavanvalkenburg)
approved these changes
Oct 29, 2026
This branch was previously deployed
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.

Motivation & Context
With
encoding_format="base64", both embedding clients callbase64.b64decodeon each payload before unpacking it as little-endian float32 values. A payload that cannot be decoded at all escapes as a barebinascii.Error(bad padding/alphabet) orUnicodeEncodeError(non-ASCII input thatstr.encode("ascii")rejects), with no reference to the input that broke — so a malformed response is indistinguishable from a bug in the client.Reported in #9511.
Relationship to #9512
#9512 (merged) already reports a misaligned payload — one whose decoded length is not a multiple of 4 — for the OpenAI client. This PR deliberately scopes itself to the remaining, still-unhandled path: a payload that cannot be decoded at all. It adds that path to the OpenAI client, and adds both guards to the Foundry client (which #9512 did not touch).
Description & Review Guide
What are the major changes?
python/packages/openai/agent_framework_openai/_embedding_client.pyandpython/packages/foundry/agent_framework_foundry/_embedding_client.py:base64.b64decodeis wrapped inexcept ValueError(the common base ofbinascii.ErrorandUnicodeEncodeError) and re-raised asIntegrationInvalidResponseException, naming the input index and preserving the original cause.Well-formed payloads are unaffected; the guard only rejects input that would have failed during
b64decodeorstruct.unpackanyway.What is the impact of these changes?
Callers that previously caught
binascii.Error/UnicodeEncodeErrornow seeIntegrationInvalidResponseException, the publicagent_framework.exceptionstype used for invalid integration responses.What do you want reviewers to focus on?
The exception type.
IntegrationInvalidResponseExceptionis the closest match in the existing hierarchy for "the service returned something we cannot interpret".Related Issue
Fixes #9511
Contribution Checklist
mainafter Python: reject misaligned base64 embedding payloads with a descriptive error #9512 landedAI Assistance
Test runs (after rebase onto main):
test_openai_embedding_client.py22 passed / 3 skipped;test_foundry_embedding_client.py32 passed / 2 skipped.