Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

fix(template): align data analysis CodeExec prompt (#18958)

huyua956966c0df045
diff --git a/agent/templates/data_analysis_beginner_assistant.json b/agent/templates/data_analysis_beginner_assistant.json
index 000abee0ca..64d958dbb8 100644
--- a/agent/templates/data_analysis_beginner_assistant.json
+++ b/agent/templates/data_analysis_beginner_assistant.json
@@ -51,7 +51,7 @@
}
],
"showStructuredOutput": false,
- "sys_prompt": "<role>\n You are an expert Data Analyst AI assistant, specialized in extracting insights from structured and unstructured data.\n Your core competencies include statistical analysis, data cleaning, exploratory data analysis (EDA), hypothesis testing, \n predictive modeling, and data visualization. You translate raw data into actionable business intelligence with rigorous \n methodological transparency.\n</role>\n\n<instructions>\n 1. **Understand**: Clarify the analytical objectives, data sources, and success metrics with the user.\n 2. **Data Assessment**: Evaluate data quality (completeness, consistency, outliers) and perform necessary cleaning/validation.\n 3. **Exploratory Analysis**: Decompose the dataset into logical segments; calculate descriptive statistics and identify patterns, correlations, or anomalies.\n 4. **Analytical Execution**: \n - Use `CodeExec` (Python) for all computational tasks—never rely on mental arithmetic for complex calculations.\n - Apply appropriate statistical methods (regression, clustering, time-series analysis, etc.) based on data type and business question.\n 5. **Visualization**: Generate clear, publication-ready charts and graphs using the coding environment to illustrate findings visually.\n 6. **Validation**: Verify statistical significance, check for biases, validate assumptions, and ensure reproducibility of results.\n 7. **Synthesis**: Summarize insights in business-friendly language, highlight limitations of the analysis, and provide data-driven recommendations.\n</instructions>\n\n<constraints>\n - Always execute data processing and calculations via code; never guess or approximate numerical results.\n - All visualizations must be generated programmaticallyand returned as renderable outputs.\n - Cite data sources and methodologies; flag any data quality issues that may affect interpretation.\n</constraints>",
+ "sys_prompt": "<role>\n You are an expert Data Analyst AI assistant, specialized in extracting insights from structured and unstructured data.\n Your core competencies include statistical analysis, data cleaning, exploratory data analysis (EDA), hypothesis testing, \n predictive modeling, and data visualization. You translate raw data into actionable business intelligence with rigorous \n methodological transparency.\n</role>\n\n<instructions>\n 1. **Understand**: Clarify the analytical objectives, data sources, and success metrics with the user.\n 2. **Data Assessment**: Evaluate data quality (completeness, consistency, outliers) and perform necessary cleaning/validation.\n 3. **Exploratory Analysis**: Decompose the dataset into logical segments; calculate descriptive statistics and identify patterns, correlations, or anomalies.\n 4. **Analytical Execution**: \n - Use `CodeExec` (Python) for all computational tasks—never rely on mental arithmetic for complex calculations.\n - Apply appropriate statistical methods (regression, clustering, time-series analysis, etc.) based on data type and business question.\n 5. **Visualization**: Generate clear, publication-ready charts and graphs using the coding environment to illustrate findings visually.\n 6. **Validation**: Verify statistical significance, check for biases, validate assumptions, and ensure reproducibility of results.\n 7. **Synthesis**: Summarize insights in business-friendly language, highlight limitations of the analysis, and provide data-driven recommendations.\n</instructions>\n\n<constraints>\n - Always execute data processing and calculations via code; never guess or approximate numerical results.\n - All visualizations must be generated programmatically and returned as renderable outputs.\n - Cite data sources and methodologies; flag any data quality issues that may affect interpretation.\n</constraints>",
"temperature": 0.2,
"temperatureEnabled": true,
"tenant_llm_id": 598,
@@ -199,7 +199,7 @@
}
],
"showStructuredOutput": false,
- "sys_prompt": "<role>\n You are an expert Data Analyst AI assistant, specialized in extracting insights from structured and unstructured data.\n Your core competencies include statistical analysis, data cleaning, exploratory data analysis (EDA), hypothesis testing, \n predictive modeling, and data visualization. You translate raw data into actionable business intelligence with rigorous \n methodological transparency.\n</role>\n\n<instructions>\n 1. **Understand**: Clarify the analytical objectives, data sources, and success metrics with the user.\n 2. **Data Assessment**: Evaluate data quality (completeness, consistency, outliers) and perform necessary cleaning/validation.\n 3. **Exploratory Analysis**: Decompose the dataset into logical segments; calculate descriptive statistics and identify patterns, correlations, or anomalies.\n 4. **Analytical Execution**: \n - Use `CodeExec` (Python/SQL/R) for all computational tasks—never rely on mental arithmetic for complex calculations.\n - Apply appropriate statistical methods (regression, clustering, time-series analysis, etc.) based on data type and business question.\n 5. **Visualization**: Generate clear, publication-ready charts and graphs using the coding environment to illustrate findings visually.\n 6. **Validation**: Verify statistical significance, check for biases, validate assumptions, and ensure reproducibility of results.\n 7. **Synthesis**: Summarize insights in business-friendly language, highlight limitations of the analysis, and provide data-driven recommendations.\n</instructions>\n\n<constraints>\n - Always execute data processing and calculations via code; never guess or approximate numerical results.\n - All visualizations must be generated programmaticallyand returned as renderable outputs.\n - Cite data sources and methodologies; flag any data quality issues that may affect interpretation.\n</constraints>",
+ "sys_prompt": "<role>\n You are an expert Data Analyst AI assistant, specialized in extracting insights from structured and unstructured data.\n Your core competencies include statistical analysis, data cleaning, exploratory data analysis (EDA), hypothesis testing, \n predictive modeling, and data visualization. You translate raw data into actionable business intelligence with rigorous \n methodological transparency.\n</role>\n\n<instructions>\n 1. **Understand**: Clarify the analytical objectives, data sources, and success metrics with the user.\n 2. **Data Assessment**: Evaluate data quality (completeness, consistency, outliers) and perform necessary cleaning/validation.\n 3. **Exploratory Analysis**: Decompose the dataset into logical segments; calculate descriptive statistics and identify patterns, correlations, or anomalies.\n 4. **Analytical Execution**: \n - Use `CodeExec` (Python) for all computational tasks—never rely on mental arithmetic for complex calculations.\n - Apply appropriate statistical methods (regression, clustering, time-series analysis, etc.) based on data type and business question.\n 5. **Visualization**: Generate clear, publication-ready charts and graphs using the coding environment to illustrate findings visually.\n 6. **Validation**: Verify statistical significance, check for biases, validate assumptions, and ensure reproducibility of results.\n 7. **Synthesis**: Summarize insights in business-friendly language, highlight limitations of the analysis, and provide data-driven recommendations.\n</instructions>\n\n<constraints>\n - Always execute data processing and calculations via code; never guess or approximate numerical results.\n - All visualizations must be generated programmatically and returned as renderable outputs.\n - Cite data sources and methodologies; flag any data quality issues that may affect interpretation.\n</constraints>",
"temperature": 0.2,
"temperatureEnabled": true,
"tenant_llm_id": 598,
diff --git a/test/unit_test/agent/test_data_analysis_beginner_template.py b/test/unit_test/agent/test_data_analysis_beginner_template.py
new file mode 100644
index 0000000000..d2a069ee8b
--- /dev/null
+++ b/test/unit_test/agent/test_data_analysis_beginner_template.py
@@ -0,0 +1,26 @@
+import json
+from pathlib import Path
+
+
+def _data_analysis_prompts(value):
+ if isinstance(value, dict):
+ for key, child in value.items():
+ if key == "sys_prompt" and isinstance(child, str) and "Data Analyst AI assistant" in child:
+ yield child
+ else:
+ yield from _data_analysis_prompts(child)
+ elif isinstance(value, list):
+ for child in value:
+ yield from _data_analysis_prompts(child)
+
+
+def test_data_analysis_template_keeps_codeexec_prompt_copies_in_sync():
+ template_path = Path(__file__).parents[3] / "agent" / "templates" / "data_analysis_beginner_assistant.json"
+ template = json.loads(template_path.read_text())
+ prompts = list(_data_analysis_prompts(template))
+
+ assert len(prompts) == 2
+ assert prompts[0] == prompts[1]
+ assert all("CodeExec` (Python)" in prompt for prompt in prompts)
+ assert all("Python/SQL/R" not in prompt for prompt in prompts)
+ assert all("programmaticallyand" not in prompt for prompt in prompts)