Skip to content

fix(LiteLlm): recognize assistant- prefix as valid OpenAI file ID#5758

Closed
nileshpatil6 wants to merge 6 commits into
google:mainfrom
nileshpatil6:fix/lite-llm-assistant-file-id-prefix
Closed

fix(LiteLlm): recognize assistant- prefix as valid OpenAI file ID#5758
nileshpatil6 wants to merge 6 commits into
google:mainfrom
nileshpatil6:fix/lite-llm-assistant-file-id-prefix

Conversation

@nileshpatil6

@nileshpatil6 nileshpatil6 commented May 19, 2026

Copy link
Copy Markdown
Contributor

Azure OpenAI files uploaded with purpose="assistants" receive IDs with an assistant- prefix (e.g. assistant-abc123). _looks_like_openai_file_id only checked for the file- prefix, causing Azure PDF attachments to be silently dropped from requests instead of being routed through the Responses API content block.

Fix: extend the startswith check to include "assistant-".

Also updated _redact_file_uri_for_log to return assistant-<redacted> for assistant- prefixed IDs, consistent with how file- IDs are handled.

Fixes #5664

Testing plan

Added unit tests in tests/unittests/models/test_litellm.py:

  • test_looks_like_openai_file_id (parametrized) covers:
    • file-abc123 -> True (existing behavior)
    • assistant-abc123 -> True (new behavior)
    • https://example.com/file.pdf -> False
    • not-a-file-id -> False
    • empty string -> False
    • FILE-abc123 -> False (case sensitive)
  • test_redact_file_uri_for_log_openai_prefixes (parametrized):
    • file-abc123 -> file-<redacted>
    • assistant-abc123 -> assistant-<redacted> (new behavior)
  • test_redact_file_uri_for_log_uses_display_name_when_provided confirms display_name short-circuits redaction.
  • test_redact_file_uri_for_log_http_url_keeps_scheme_and_tail confirms HTTP URLs still redact host but preserve scheme and filename.

Run locally with:

pytest tests/unittests/models/test_litellm.py -k "looks_like_openai_file_id or redact_file_uri_for_log"

@adk-bot adk-bot added the models [Component] Issues related to model support label May 20, 2026
@adk-bot

adk-bot commented May 20, 2026

Copy link
Copy Markdown
Collaborator

Response from ADK Triaging Agent

Hello @nileshpatil6, thank you for creating this PR to fix the Azure OpenAI assistant prefix issue!

To help our reviewers process this contribution more efficiently and maintain code quality, could you please address the following items from our Contribution Guidelines:

  1. Unit Tests / Testing Plan:
    • Please add or update unit tests to cover this new file ID prefix (assistant-) and verify that redaction behaves correctly under tests/unittests/.
    • Please include a testing plan section in your PR description detailing how you verified the changes (such as a summary of passed pytest results).
  2. Logs or Screenshots:
    • As this is a bug fix, please provide logs or verification output showing how the file is successfully handled now compared to before.

These details will help ensure we prevent regressions and streamline the review process. Thank you again for your contribution!

@rohityan rohityan self-assigned this May 20, 2026
@rohityan rohityan added the request clarification [Status] The maintainer need clarification or more information from the author label May 20, 2026
@rohityan

Copy link
Copy Markdown
Collaborator

Hi @nileshpatil6 , Thank you for your contribution! We appreciate you taking the time to submit this pull request. Can you please fix the failing unit tests before we can proceed with the review.

@nileshpatil6

Copy link
Copy Markdown
Contributor Author

hey @rohityan thanks for the review. added unit tests in tests/unittests/models/test_litellm.py covering both the new assistant- prefix recognition and the redact helper. all 10 new tests pass locally along with the rest of test_litellm.py (268 passed, 1 skipped).

the two failing checks on the run dont seem related to this PR:

  • test (3.10): only test_metrics in tests/unittests/telemetry/test_functional.py fails (asserts 2 == 1 on agent metric points), the file isnt touched here
  • pre-commit: formatting diff in tests/.../test_list_gcp_projects_import_error which also isnt touched

happy to look into those if you want but they seem like flakes from main. let me know if anything else needed

@nileshpatil6

Copy link
Copy Markdown
Contributor Author

Hi @rohityan, thanks for keeping this synced with main. Quick check in from my side. The unit tests you asked for are in tests/unittests/models/test_litellm.py, covering the assistant- prefix case along with the existing ones, and all the CI checks are green right now. Is there anything else you want me to change, or is it good to go? Happy to make any tweaks if needed.

@i-yliu i-yliu assigned i-yliu and unassigned rohityan Jun 17, 2026
copybara-service Bot pushed a commit that referenced this pull request Jun 17, 2026
Merge #5758

Azure OpenAI files uploaded with `purpose="assistants"` receive IDs with an `assistant-` prefix (e.g. `assistant-abc123`). `_looks_like_openai_file_id` only checked for the `file-` prefix, causing Azure PDF attachments to be silently dropped from requests instead of being routed through the Responses API content block.

Fix: extend the `startswith` check to include `"assistant-"`.

Also updated `_redact_file_uri_for_log` to return `assistant-<redacted>` for `assistant-` prefixed IDs, consistent with how `file-` IDs are handled.

Fixes #5664

## Testing plan

Added unit tests in `tests/unittests/models/test_litellm.py`:

- `test_looks_like_openai_file_id` (parametrized) covers:
  - `file-abc123` -> True (existing behavior)
  - `assistant-abc123` -> True (new behavior)
  - `https://example.com/file.pdf` -> False
  - `not-a-file-id` -> False
  - empty string -> False
  - `FILE-abc123` -> False (case sensitive)
- `test_redact_file_uri_for_log_openai_prefixes` (parametrized):
  - `file-abc123` -> `file-<redacted>`
  - `assistant-abc123` -> `assistant-<redacted>` (new behavior)
- `test_redact_file_uri_for_log_uses_display_name_when_provided` confirms `display_name` short-circuits redaction.
- `test_redact_file_uri_for_log_http_url_keeps_scheme_and_tail` confirms HTTP URLs still redact host but preserve scheme and filename.

Run locally with:
```
pytest tests/unittests/models/test_litellm.py -k "looks_like_openai_file_id or redact_file_uri_for_log"
```

Co-authored-by: George Weale <gweale@google.com>
COPYBARA_INTEGRATE_REVIEW=#5758 from nileshpatil6:fix/lite-llm-assistant-file-id-prefix 6b2afd7
PiperOrigin-RevId: 933898777
@adk-bot

adk-bot commented Jun 17, 2026

Copy link
Copy Markdown
Collaborator

Thank you @nileshpatil6 for your contribution! 🎉

Your changes have been successfully imported and merged via Copybara in commit 796964a.

Closing this PR as the changes are now in the main branch.

@adk-bot adk-bot added the merged [Status] This PR is merged label Jun 17, 2026
@adk-bot adk-bot closed this Jun 17, 2026
copybara-service Bot pushed a commit that referenced this pull request Jun 17, 2026
Merge #5758

Original PR by @nileshpatil6 (Nilesh Patil <128893479+nileshpatil6@users.noreply.github.com>)

Azure OpenAI files receive IDs with an `assistant-` prefix (e.g. `assistant-abc123`) or `file-` prefix. When `_looks_like_openai_file_id` recognizes an `assistant-` prefixed ID (e.g., `assistant-abc123`) or `file-` prefixed ID, `_redact_file_uri_for_log` defaulted to logging both as `file - <redacted>`.

Fix: refactor `_redact_file_uri_for_log` to dynamically extract file ID prefixes (`file-`, `assistant-`). This ensures compatibility with both current prefixes and future OpenAI/Azure file ID types.

Fixes #5664

Co-authored-by: Yi Liu <yiliuly@google.com>
PiperOrigin-RevId: 933931477
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged [Status] This PR is merged models [Component] Issues related to model support request clarification [Status] The maintainer need clarification or more information from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Title LiteLlm: Azure OpenAI file_id with assistant- prefix bypasses Responses-API content block

4 participants