adithaf7 commited on
Commit
daffcab
Β·
1 Parent(s): 31d01ed

feat: Improve error handling in ExecutorAgent by enhancing prompt clarity and response guidance for insufficient data scenarios

Browse files
Files changed (2) hide show
  1. README.md +3 -1
  2. backend/app/agents/executor.py +8 -7
README.md CHANGED
@@ -168,12 +168,14 @@ User: "What about their locations?"
168
  AI: [Understands context from previous query]
169
 
170
  "Calculate Return Rate by Region. Don't give any chart"
171
- β†’ Returns only table (respects preference)
172
 
173
  "hi" or "how are you"
174
  β†’ Responds conversationally without triggering data analysis
175
  ```
176
 
 
 
177
  ---
178
 
179
  ## πŸ”‘ Key Technical Features
 
168
  AI: [Understands context from previous query]
169
 
170
  "Calculate Return Rate by Region. Don't give any chart"
171
+ β†’ ⚠️ Note: Sample dataset lacks return data - AI will explain limitation and suggest alternatives
172
 
173
  "hi" or "how are you"
174
  β†’ Responds conversationally without triggering data analysis
175
  ```
176
 
177
+ > **πŸ“ Note on Test Prompt #10:** The challenge includes "Calculate Return Rate" but the Sample Superstore.csv doesn't contain return/refund data. The AI correctly identifies this limitation and explains what data would be needed. This demonstrates intelligent error handling.
178
+
179
  ---
180
 
181
  ## πŸ”‘ Key Technical Features
backend/app/agents/executor.py CHANGED
@@ -646,19 +646,20 @@ Do NOT import any system modules. Only use: pandas, matplotlib.pyplot, numpy.
646
 
647
  # Build the prompt for Gemini
648
  if is_insufficient_data:
649
- prompt = f"""You are a data analysis assistant. The user asked a question that cannot be fully answered with the available data.
650
 
651
  User Question: {question}
652
 
653
- Available Data Schema:
654
- - Columns: {columns_info}
655
- - Shape: {data_shape}
656
 
657
- Analysis Plan (shows what's missing):
658
  {plan}
659
 
660
- Please provide a helpful response explaining what data would be needed to answer this question, and if possible, suggest what analysis CAN be done with the available data.
661
- Keep your response concise (2-3 sentences)."""
 
 
 
662
  else:
663
  # Perform basic pandas analysis to get actual results
664
  analysis_result = self._perform_pandas_analysis(df, question, plan)
 
646
 
647
  # Build the prompt for Gemini
648
  if is_insufficient_data:
649
+ prompt = f"""You are a helpful data analysis assistant. The user asked a question that cannot be answered with the current dataset.
650
 
651
  User Question: {question}
652
 
653
+ Available Data Columns: {columns_info}
 
 
654
 
655
+ Analysis Plan Notes:
656
  {plan}
657
 
658
+ Provide a friendly response that:
659
+ 1. Explains what data/column is missing (e.g., "Returns" or "Return Status")
660
+ 2. Suggests what alternative analysis CAN be done with the current data (e.g., sales by region, profit trends, etc.)
661
+
662
+ Keep response concise, helpful, and actionable (3-4 sentences max)."""
663
  else:
664
  # Perform basic pandas analysis to get actual results
665
  analysis_result = self._perform_pandas_analysis(df, question, plan)