Skip to content

enhancement: Add query length guard in handle_chat #83

Open

Description

@QuantumByte-01

Problem

handle_chat accepts any length query and passes it directly to Gemini with no cap. Pasting a full paper or very long text will hit token limits and return a cryptic error.

Fix

Add a simple guard at the top of handle_chat:

MAX_QUERY_LENGTH = int(os.getenv("MAX_QUERY_LENGTH", "2000"))
if len(query) > MAX_QUERY_LENGTH:
    return f"Query too long ({len(query)} chars). Please keep it under {MAX_QUERY_LENGTH} characters."

Add MAX_QUERY_LENGTH to .env.template.

Activity

  1. pragati-0208 commented on Mar 13, 2026

    @pragati-0208
    Contributor

    hello,
    I’d like to work on this issue. Could you please assign it to me?

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions