Skip to content

Fix: return 404 for invalid app_name in /run and /run_sse endpoints#5376

Open
AbhishekMauryaGEEK wants to merge 3 commits intogoogle:mainfrom
AbhishekMauryaGEEK:fix/adk-handle-invalid-app-name
Open

Fix: return 404 for invalid app_name in /run and /run_sse endpoints#5376
AbhishekMauryaGEEK wants to merge 3 commits intogoogle:mainfrom
AbhishekMauryaGEEK:fix/adk-handle-invalid-app-name

Conversation

@AbhishekMauryaGEEK
Copy link
Copy Markdown

Fixes #5374

Summary

Fixes improper error handling in the ADK FastAPI server where invalid
app_name values caused unhandled exceptions and resulted in HTTP 500
responses.

This change ensures that invalid or non-existent app_name inputs return a
controlled 404 Not Found response instead.


Problem

The endpoints:

  • POST /run
  • POST /run_sse

call get_runner_async(app_name), which raises a ValueError when the agent
cannot be found.

This exception was not handled at the API layer, causing FastAPI to return a
500 Internal Server Error.


Solution

Wrap the get_runner_async call in a try/except block and convert
ValueError into a 404 HTTPException.

Example:

try:
    runner = await self.get_runner_async(req.app_name)
except ValueError as e:
    raise HTTPException(status_code=404, detail=str(e)) from e

This aligns the response with expected API semantics for missing resources.

Error Handling Improvements:

  • Added a try/except block to handle ValueError when calling get_runner_async, returning a 404 HTTP response if the specified app is not found.

Logging Changes:

  • Removed info and debug logging of generated events from the run_agent endpoint, simplifying the response logic.
curl -X POST http://127.0.0.1:8000/run \
  -H "Content-Type: application/json" \
  -d '{
    "app_name": "INVALID",
    "user_id": "u1",
    "session_id": "s1",
    "message": "hello"
  }' 
HTTP 500 Internal Server Error
HTTP 404 Not Found
{
  "detail": "Agent not found: 'INVALID'"
}

Notes

-- No changes to existing successful flows
-- No additional logging or refactoring introduced
-- Change is minimal and scoped strictly to error handling

Testing

-- Verified /run returns 404 for invalid app_name
-- Verified /run_sse returns 404 for invalid app_name
-- Confirmed no regression for valid agents

@google-cla
Copy link
Copy Markdown

google-cla bot commented Apr 17, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@adk-bot adk-bot added the web [Component] This issue will be transferred to adk-web label Apr 17, 2026
@AbhishekMauryaGEEK
Copy link
Copy Markdown
Author

Hi maintainers, this PR fixes improper error handling for invalid app_name
(returning 404 instead of 500).

CLA has been signed and checks are passing.
Kindly review when convenient.

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

Labels

web [Component] This issue will be transferred to adk-web

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unhandled exception for invalid app_name leads to 500 response

2 participants