Skip to content

Add input validation to /chat/query endpoint#118

Merged
zhangdjr merged 2 commits intoimprove-chatbotfrom
copilot/sub-pr-116-again
Feb 10, 2026
Merged

Add input validation to /chat/query endpoint#118
zhangdjr merged 2 commits intoimprove-chatbotfrom
copilot/sub-pr-116-again

Conversation

Copy link

Copilot AI commented Feb 10, 2026

The /chat/query endpoint was passing unvalidated input directly to the LLM, causing 500 errors when clients sent empty payloads or non-string values.

Changes

  • Added validation to ensure query is a non-empty string before invoking the LLM chain
  • Returns 400 with clear error message for invalid input
@app.post("/chat/query")
async def chat_query(req: Request):
    # ... chatbot initialization ...
    body = await req.json()
    query = body.get("query")
    if not isinstance(query, str) or not query.strip():
        raise HTTPException(status_code=400, detail="Query must be a non-empty string.")
    result = chain.invoke({"messages": [{"role": "user", "content": query}]})
    # ...

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: zhangdjr <123129802+zhangdjr@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP to address feedback on chatbot improvements Add input validation to /chat/query endpoint Feb 10, 2026
Copilot AI requested a review from zhangdjr February 10, 2026 21:07
@zhangdjr zhangdjr marked this pull request as ready for review February 10, 2026 21:12
@zhangdjr zhangdjr merged commit db2e6c7 into improve-chatbot Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants