diff --git a/examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/chatui.py b/examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/chatui.py index 73e7378f0..7990ce19e 100644 --- a/examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/chatui.py +++ b/examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/chatui.py @@ -245,11 +245,14 @@ def feedback(): # using input text box. @bp.route("/result", methods=["GET", "POST"]) def result(): - if request.method == "POST": - question = request.form["question"] - return ask_model(question, agent=docs_agent, template=app_template) - else: + if request.method != "POST": + return redirect(url_for(redirect_index)) + + question = request.form.get("question", "").strip() + if not question: return redirect(url_for(redirect_index)) + + return ask_model(question, agent=docs_agent, template=app_template) # Render a response page when the user clicks a question # from the related questions list.