Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.

Commit 777d554

Browse files
committed
chore: handle empty messages
1 parent ffcbfe8 commit 777d554

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

rag-core-api/src/rag_core_api/impl/graph/chat_graph.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ async def ainvoke(
126126
- The method processes the chat history based on the settings defined in `_chat_history_settings`.
127127
- The history is formatted and included in the `AnswerGraphState`.
128128
"""
129+
if not graph_input.message.strip():
130+
return ChatResponse(
131+
answer=self._error_messages.empty_message,
132+
citations=[],
133+
finish_reason=self._error_messages.empty_message,
134+
)
135+
129136
history_of_interest = []
130137
if graph_input.history and graph_input.history.messages:
131138
history_of_interest = graph_input.history.messages[-self._chat_history_settings.limit :]

rag-core-api/src/rag_core_api/impl/settings/error_messages.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class ErrorMessages(BaseSettings):
1818
Default message for harmful or inappropriate questions.
1919
no_answer_found : str
2020
Default message when no answer is found with the given context.
21+
empty_message : str
22+
Default message when an empty question is provided.
2123
"""
2224

2325
class Config:
@@ -40,3 +42,5 @@ class Config:
4042
no_answer_found: str = Field(
4143
default="Es tut mir leid, mit dem mir bereitgestellten Kontext konnte ich keine Antwort finden."
4244
)
45+
46+
empty_message: str = Field(default="Es tut mir leid, ich kann keine leere Frage beantworten.")

0 commit comments

Comments
 (0)