Skip to content

enhancement: Add query length guard in handle_chat #83

@QuantumByte-01

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.

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