Python: malformed base64 embedding payload raises a bare struct error with no context · Issue #9511 · microsoft/agent-framework · GitHub
Skip to content

Python: malformed base64 embedding payload raises a bare struct error with no context #9511

Open

Description

Description

With encoding_format set to base64, OpenAIEmbeddingClient.get_embeddings decodes each payload with struct.unpack sized as len(raw) // 4. When the decoded byte length is not a multiple of 4 (a truncated or malformed response), the buffer is longer than the format expects and the call fails with a bare struct.error: unpack requires a buffer of X bytes, with no wrapping and no indication of which input's embedding broke.

Observed Behavior

A response item whose base64 payload decodes to, say, 5 bytes raises struct.error straight out of get_embeddings.

Expected Behavior

The client should reject the payload with a descriptive error naming the input index and the decoded length, so callers can tell a malformed response apart from a client bug.

Reproduction Steps

  1. Request embeddings with options={"encoding_format": "base64"}.
  2. Have the endpoint (or a proxy) return a payload whose decoded length is not divisible by 4.
  3. get_embeddings raises struct.error.

Minimal Reproduction

raw = base64.b64encode(struct.pack("<1f", 0.5) + b"\\x00").decode()
# served as the embedding string for one item

Error Messages and Stack Traces

struct.error: unpack requires a buffer of 4 bytes

Package Versions

agent_framework_openai from main.

Python Version

3.11

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    pythonUsage: [Issues, PRs], Target: PythontriageUsage: [Issues], Target: All issues that still need to be triaged

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions