Skip to content

LLMOutput Fix: generate presigned URL for audio output in LLM call response#865

Merged
Ayush8923 merged 3 commits into
mainfrom
chore/patch-fix-llm-call-output-audio-url
May 20, 2026
Merged

LLMOutput Fix: generate presigned URL for audio output in LLM call response#865
Ayush8923 merged 3 commits into
mainfrom
chore/patch-fix-llm-call-output-audio-url

Conversation

@vprashrex
Copy link
Copy Markdown
Collaborator

@vprashrex vprashrex commented May 20, 2026

ISSUE: #866

Summary

GET /llm/call/{job_id} was broken for all audio (TTS) jobs. When audio is uploaded to S3 during job execution, jobs.py stores format: "uri" in the DB as an internal marker for "this is an S3 path, generate a presigned URL before serving." The AudioContent pydantic model (used in LLMResponse) only accepts "base64" or "url", so deserialization always failed with a validation error.

Fix:

llm_call.content is dict[str, Any] (raw JSONB from DB). Pydantic hasn't parsed it yet, and parsing is exactly what fails when format == "uri". The fix must happen on the raw dict before the model is constructed.

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

Notes

Please add here if any other information is required for the reviewer.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

📝 Walkthrough

Walkthrough

The LLM call status endpoint now post-processes successful responses containing audio outputs. When an output has type "audio" and format "uri", the handler generates a signed URL via cloud storage and rewrites the payload to format "url" with the signed value. If signing fails, it logs a warning and clears the audio value. The response uses the (possibly modified) output payload instead of the original content.

Changes

Audio Output Signing

Layer / File(s) Summary
Audio URL signing post-processor
backend/app/api/routes/llm.py
Import get_cloud_storage and add post-processing logic to detect audio outputs with URI format, generate signed URLs via cloud storage, and update the response payload format to "url" with the signed value. On signing failure, log a warning and clear the audio value.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🎵 A rabbit hops through audio streams,
Converting URIs to cloud-signed dreams,
With signed URLs now safe and tight,
The soundtracks flow through the API night! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: generating presigned URLs for audio output in LLM call responses, which aligns with the file summary showing post-processing of audio items with URI format conversion.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/patch-fix-llm-call-output-audio-url

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/app/api/routes/llm.py`:
- Around line 154-172: The handler is mutating llm_call.content in place via the
output_payload alias, which can persist an expiring signed URL back into the DB;
instead, make a shallow/deep copy of llm_call.content into a new local variable
(e.g., output_payload_copy) before inspecting/modifying it, update
output_payload_copy["content"]["value"] and ["content"]["format"] when calling
get_cloud_storage(session, project_id) and storage.get_signed_url(...), and
return/send the copied payload rather than writing back to llm_call.content;
apply the same non-mutating copy approach for the similar code at the other
occurrence around line 179.
- Around line 168-170: The log message uses the wrong function-prefix; update
the logger.warning call that currently prefixes "[get_llm_call]" to use the
correct function name "[get_llm_call_status]" (and any similar log lines in
get_llm_call_status) so all log messages are prefixed with the actual function
name per guidelines; locate the logger.warning in get_llm_call_status and change
the square-bracket prefix accordingly while keeping the rest of the message and
error variable (e) intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: e5a91970-52b8-4c62-8b5a-be1a4a93edbe

📥 Commits

Reviewing files that changed from the base of the PR and between 7a22c28 and 19834c0.

📒 Files selected for processing (1)
  • backend/app/api/routes/llm.py

Comment thread backend/app/api/routes/llm.py Outdated
Comment thread backend/app/api/routes/llm.py
@vprashrex vprashrex linked an issue May 20, 2026 that may be closed by this pull request
@Ayush8923
Copy link
Copy Markdown
Collaborator

@vprashrex test cases failing, please check.

@Ayush8923 Ayush8923 merged commit f1880b5 into main May 20, 2026
3 checks passed
@Ayush8923 Ayush8923 deleted the chore/patch-fix-llm-call-output-audio-url branch May 20, 2026 07:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TTS: Fix polling validation error

2 participants