A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
update system prompt & claude.md (#6437)
Shahmir Varqha3e80dc9a1408
diff --git a/docs/_static/CLAUDE.md b/docs/_static/CLAUDE.mdindex 38d8c30322..55ee76a789 100644--- a/docs/_static/CLAUDE.md+++ b/docs/_static/CLAUDE.md@@ -46,7 +46,7 @@ Marimo's reactivity means:<data_handling>-- Use pandas for data manipulation+- Use polars for data manipulation- Implement proper data validation- Handle missing values appropriately- Use efficient data structures@@ -56,7 +56,7 @@ Marimo's reactivity means:<visualization>- For matplotlib: use plt.gca() as the last expression instead of plt.show()- For plotly: return the figure object directly-- For altair: return the chart object directly+- For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair.- Include proper labels, titles, and color schemes- Make visualizations interactive where appropriate</visualization>@@ -79,7 +79,7 @@ Marimo's reactivity means:</data_sources><sql>-- When writing duckdb, prefer using marimo's SQL cells, which start with _df = mo.sql(query)+- When writing duckdb, prefer using marimo's SQL cells, which start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.- See the SQL with duckdb example for an example on how to do this- Don't add comments in cells that use mo.sql()- Consider using \`vega_datasets\` for common example datasets@@ -132,7 +132,8 @@ Common issues and solutions:<example title="Basic UI with reactivity"># Cell 1import marimo as mo-import matplotlib.pyplot as plt+import altair as alt+import polars as plimport numpy as np# Cell 2@@ -151,59 +152,64 @@ n_points # Display the sliderx = np.random.rand(n_points.value)y = np.random.rand(n_points.value)-plt.figure(figsize=(8, 6))-plt.scatter(x, y, alpha=0.7)-plt.title(f"Scatter plot with {n_points.value} points")-plt.xlabel("X axis")-plt.ylabel("Y axis")-plt.gca() # Return the current axes to display the plot+df = pl.DataFrame({"x": x, "y": y})++chart = alt.Chart(df).mark_circle(opacity=0.7).encode(+ x=alt.X('x', title='X axis'),+ y=alt.Y('y', title='Y axis')+).properties(+ title=f"Scatter plot with {n_points.value} points",+ width=400,+ height=300+)++chart</example><example title="Data explorer"># Cell 1import marimo as mo-import pandas as pd+import polars as plfrom vega_datasets import data# Cell 2# Load and display dataset with interactive explorer-cars_df = data.cars()+cars_df = pl.DataFrame(data.cars())mo.ui.data_explorer(cars_df)</example><example title="Multiple UI elements"># Cell 1import marimo as mo-import pandas as pd-import matplotlib.pyplot as plt-import seaborn as sns+import polars as pl+import altair as alt# Cell 2# Load dataset-iris = sns.load_dataset('iris')+iris = pl.read_csv("hf://datasets/scikit-learn/iris/Iris.csv")# Cell 3# Create UI elementsspecies_selector = mo.ui.dropdown(- options=["All"] + iris["species"].unique().tolist(),+ options=["All"] + iris["Species"].unique().to_list(),value="All",- label="Species"+ label="Species",)x_feature = mo.ui.dropdown(- options=iris.select_dtypes('number').columns.tolist(),- value="sepal_length",- label="X Feature"+ options=iris.select(pl.col(pl.Float64, pl.Int64)).columns,+ value="SepalLengthCm",+ label="X Feature",)y_feature = mo.ui.dropdown(- options=iris.select_dtypes('number').columns.tolist(),- value="sepal_width",- label="Y Feature"+ options=iris.select(pl.col(pl.Float64, pl.Int64)).columns,+ value="SepalWidthCm",+ label="Y Feature",)# Display UI elements in a horizontal stack@@ -214,36 +220,45 @@ mo.hstack([species_selector, x_feature, y_feature])# Filter data based on selection-filtered_data = iris if species_selector.value == "All" else iris[iris["species"] == species_selector.value]+filtered_data = iris if species_selector.value == "All" else iris.filter(pl.col("Species") == species_selector.value)# Create visualization based on UI selections-plt.figure(figsize=(10, 6))-sns.scatterplot(- data=filtered_data,- x=x_feature.value,- y=y_feature.value,- hue="species"+chart = alt.Chart(filtered_data).mark_circle().encode(+ x=alt.X(x_feature.value, title=x_feature.value),+ y=alt.Y(y_feature.value, title=y_feature.value),+ color='Species'+).properties(+ title=f"{y_feature.value} vs {x_feature.value}",+ width=500,+ height=400)-plt.title(f"{y_feature.value} vs {x_feature.value}")-plt.gca()++chart</example><example title="Interactive chart with Altair"># Cell 1import marimo as moimport altair as alt-import pandas as pd+import polars as pl# Cell 2# Load dataset-cars_df = pd.read_csv('<https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json>')-_chart = alt.Chart(cars_df).mark_point().encode(- x='Horsepower',- y='Miles_per_Gallon',- color='Origin',+weather = pl.read_csv("https://raw.githubusercontent.com/vega/vega-datasets/refs/heads/main/data/weather.csv")+weather_dates = weather.with_columns(+ pl.col("date").str.strptime(pl.Date, format="%Y-%m-%d")+)+_chart = (+ alt.Chart(weather_dates)+ .mark_point()+ .encode(+ x="date:T",+ y="temp_max",+ color="location",+ ))chart = mo.ui.altair_chart(_chart)@@ -279,16 +294,21 @@ else:<example title="SQL with duckdb"># Cell 1import marimo as mo+import polars as pl# Cell 2# Load dataset-cars_df = pd.read_csv('<https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json>')+weather = pl.read_csv("https://raw.githubusercontent.com/vega/vega-datasets/refs/heads/main/data/weather.csv")# Cell 3-_df = mo.sql("SELECT * from cars_df WHERE Miles_per_Gallon > 20")+seattle_weather_df = mo.sql(+ f"""+ SELECT * FROM weather WHERE location = 'Seattle';+ """+)</example><example title="Writing LaTeX in markdown">@@ -297,10 +317,11 @@ import marimo as mo# Cell 2-mo.md(r"""-+mo.md(+ r"""The quadratic function $f$ is defined as$$f(x) = x^2.$$-""")+"""+)</example>diff --git a/frontend/src/components/chat/acp/__tests__/__snapshots__/prompt.test.ts.snap b/frontend/src/components/chat/acp/__tests__/__snapshots__/prompt.test.ts.snapindex 7d544e8242..7977335383 100644--- a/frontend/src/components/chat/acp/__tests__/__snapshots__/prompt.test.ts.snap+++ b/frontend/src/components/chat/acp/__tests__/__snapshots__/prompt.test.ts.snap@@ -52,7 +52,7 @@ exports[`getAgentPrompt > should generate complete agent prompt with default fil## Best Practices<data_handling>- - Use pandas for data manipulation+ - Use polars for data manipulation- Implement proper data validation- Handle missing values appropriately- Use efficient data structures@@ -62,7 +62,7 @@ exports[`getAgentPrompt > should generate complete agent prompt with default fil<visualization>- For matplotlib: use plt.gca() as the last expression instead of plt.show()- For plotly: return the figure object directly- - For altair: return the chart object directly+ - For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair.- Include proper labels, titles, and color schemes- Make visualizations interactive where appropriate</visualization>@@ -76,7 +76,7 @@ exports[`getAgentPrompt > should generate complete agent prompt with default fil</ui_elements><sql>- - When writing duckdb, prefer using marimo's SQL cells, which start with _df = mo.sql(query)+ - When writing duckdb, prefer using marimo's SQL cells, which start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.- See the SQL with duckdb example for an example on how to do this- Don't add comments in cells that use mo.sql()- Consider using \`vega_datasets\` for common example datasets@@ -146,7 +146,8 @@ exports[`getAgentPrompt > should generate complete agent prompt with default fil@app.celldef _():import marimo as mo- import matplotlib.pyplot as plt+ import altair as alt+ import polars as plimport numpy as npreturn@@ -161,12 +162,18 @@ exports[`getAgentPrompt > should generate complete agent prompt with default filx = np.random.rand(n_points.value)y = np.random.rand(n_points.value)- plt.figure(figsize=(8, 6))- plt.scatter(x, y, alpha=0.7)- plt.title(f"Scatter plot with {n_points.value} points")- plt.xlabel("X axis")- plt.ylabel("Y axis")- plt.gca()+ df = pl.DataFrame({"x": x, "y": y})++ chart = alt.Chart(df).mark_circle(opacity=0.7).encode(+ x=alt.X('x', title='X axis'),+ y=alt.Y('y', title='Y axis')+ ).properties(+ title=f"Scatter plot with {n_points.value} points",+ width=400,+ height=300+ )++ chartreturn</example>@@ -176,13 +183,13 @@ exports[`getAgentPrompt > should generate complete agent prompt with default fil@app.celldef _():import marimo as mo- import pandas as pd+ import polars as plfrom vega_datasets import datareturn@app.celldef _():- cars_df = data.cars()+ cars_df = pl.DataFrame(data.cars())mo.ui.data_explorer(cars_df)return@@ -193,49 +200,50 @@ exports[`getAgentPrompt > should generate complete agent prompt with default fil@app.celldef _():import marimo as mo- import pandas as pd- import matplotlib.pyplot as plt- import seaborn as sns+ import polars as pl+ import altair as altreturn@app.celldef _():- iris = sns.load_dataset('iris')+ iris = pl.read_csv("hf://datasets/scikit-learn/iris/Iris.csv")return@app.celldef _():species_selector = mo.ui.dropdown(- options=["All"] + iris["species"].unique().tolist(),+ options=["All"] + iris["Species"].unique().to_list(),value="All",- label="Species"+ label="Species",)x_feature = mo.ui.dropdown(- options=iris.select_dtypes('number').columns.tolist(),- value="sepal_length",- label="X Feature"+ options=iris.select(pl.col(pl.Float64, pl.Int64)).columns,+ value="SepalLengthCm",+ label="X Feature",)y_feature = mo.ui.dropdown(- options=iris.select_dtypes('number').columns.tolist(),- value="sepal_width",- label="Y Feature"+ options=iris.select(pl.col(pl.Float64, pl.Int64)).columns,+ value="SepalWidthCm",+ label="Y Feature",)mo.hstack([species_selector, x_feature, y_feature])return@app.celldef _():- filtered_data = iris if species_selector.value == "All" else iris[iris["species"] == species_selector.value]-- plt.figure(figsize=(10, 6))- sns.scatterplot(- data=filtered_data,- x=x_feature.value,- y=y_feature.value,- hue="species"+ filtered_data = iris if species_selector.value == "All" else iris.filter(pl.col("Species") == species_selector.value)++ chart = alt.Chart(filtered_data).mark_circle().encode(+ x=alt.X(x_feature.value, title=x_feature.value),+ y=alt.Y(y_feature.value, title=y_feature.value),+ color='Species'+ ).properties(+ title=f"{y_feature.value} vs {x_feature.value}",+ width=500,+ height=400)- plt.title(f"{y_feature.value} vs {x_feature.value}")- plt.gca()++ chartreturn</example>@@ -260,17 +268,24 @@ exports[`getAgentPrompt > should generate complete agent prompt with default fildef _():import marimo as moimport altair as alt- import pandas as pd+ import polars as plreturn@app.celldef _():# Load dataset- cars_df = pd.read_csv('<https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json>')- _chart = alt.Chart(cars_df).mark_point().encode(- x='Horsepower',- y='Miles_per_Gallon',- color='Origin',+ weather = pl.read_csv("https://raw.githubusercontent.com/vega/vega-datasets/refs/heads/main/data/weather.csv")+ weather_dates = weather.with_columns(+ pl.col("date").str.strptime(pl.Date, format="%Y-%m-%d")+ )+ _chart = (+ alt.Chart(weather_dates)+ .mark_point()+ .encode(+ x="date:T",+ y="temp_max",+ color="location",+ ))return@@ -319,17 +334,21 @@ exports[`getAgentPrompt > should generate complete agent prompt with default fil@app.celldef _():import marimo as mo- import pandas as pd+ import polars as plreturn@app.celldef _():- cars_df = pd.read_csv('<https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json>')+ weather = pl.read_csv('https://raw.githubusercontent.com/vega/vega-datasets/refs/heads/main/data/weather.csv')return@app.celldef _():- _df = mo.sql("SELECT * from cars_df WHERE Miles_per_Gallon > 20")+ seattle_weather_df = mo.sql(+ f"""+ SELECT * FROM weather WHERE location = 'Seattle';+ """+ )return</example>"diff --git a/frontend/src/components/chat/acp/prompt.ts b/frontend/src/components/chat/acp/prompt.tsindex 2f257d18a4..975193b286 100644--- a/frontend/src/components/chat/acp/prompt.ts+++ b/frontend/src/components/chat/acp/prompt.ts@@ -52,7 +52,7 @@ export function getAgentPrompt(filename: string) {## Best Practices<data_handling>- - Use pandas for data manipulation+ - Use polars for data manipulation- Implement proper data validation- Handle missing values appropriately- Use efficient data structures@@ -62,7 +62,7 @@ export function getAgentPrompt(filename: string) {<visualization>- For matplotlib: use plt.gca() as the last expression instead of plt.show()- For plotly: return the figure object directly- - For altair: return the chart object directly+ - For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair.- Include proper labels, titles, and color schemes- Make visualizations interactive where appropriate</visualization>@@ -76,7 +76,7 @@ export function getAgentPrompt(filename: string) {</ui_elements><sql>- - When writing duckdb, prefer using marimo's SQL cells, which start with _df = mo.sql(query)+ - When writing duckdb, prefer using marimo's SQL cells, which start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.- See the SQL with duckdb example for an example on how to do this- Don't add comments in cells that use mo.sql()- Consider using \`vega_datasets\` for common example datasets@@ -144,7 +144,8 @@ export function getAgentPrompt(filename: string) {${formatCells([`import marimo as mo- import matplotlib.pyplot as plt+ import altair as alt+ import polars as plimport numpy as np`,`@@ -155,12 +156,18 @@ export function getAgentPrompt(filename: string) {x = np.random.rand(n_points.value)y = np.random.rand(n_points.value)- plt.figure(figsize=(8, 6))- plt.scatter(x, y, alpha=0.7)- plt.title(f"Scatter plot with {n_points.value} points")- plt.xlabel("X axis")- plt.ylabel("Y axis")- plt.gca()+ df = pl.DataFrame({"x": x, "y": y})++ chart = alt.Chart(df).mark_circle(opacity=0.7).encode(+ x=alt.X('x', title='X axis'),+ y=alt.Y('y', title='Y axis')+ ).properties(+ title=f"Scatter plot with {n_points.value} points",+ width=400,+ height=300+ )++ chart`,])}</example>@@ -169,11 +176,11 @@ export function getAgentPrompt(filename: string) {${formatCells([`import marimo as mo- import pandas as pd+ import polars as plfrom vega_datasets import data`,`- cars_df = data.cars()+ cars_df = pl.DataFrame(data.cars())mo.ui.data_explorer(cars_df)`,])}@@ -183,43 +190,44 @@ export function getAgentPrompt(filename: string) {${formatCells([`import marimo as mo- import pandas as pd- import matplotlib.pyplot as plt- import seaborn as sns+ import polars as pl+ import altair as alt`,`- iris = sns.load_dataset('iris')+ iris = pl.read_csv("hf://datasets/scikit-learn/iris/Iris.csv")`,`species_selector = mo.ui.dropdown(- options=["All"] + iris["species"].unique().tolist(),+ options=["All"] + iris["Species"].unique().to_list(),value="All",- label="Species"+ label="Species",)x_feature = mo.ui.dropdown(- options=iris.select_dtypes('number').columns.tolist(),- value="sepal_length",- label="X Feature"+ options=iris.select(pl.col(pl.Float64, pl.Int64)).columns,+ value="SepalLengthCm",+ label="X Feature",)y_feature = mo.ui.dropdown(- options=iris.select_dtypes('number').columns.tolist(),- value="sepal_width",- label="Y Feature"+ options=iris.select(pl.col(pl.Float64, pl.Int64)).columns,+ value="SepalWidthCm",+ label="Y Feature",)mo.hstack([species_selector, x_feature, y_feature])`,`- filtered_data = iris if species_selector.value == "All" else iris[iris["species"] == species_selector.value]-- plt.figure(figsize=(10, 6))- sns.scatterplot(- data=filtered_data,- x=x_feature.value,- y=y_feature.value,- hue="species"+ filtered_data = iris if species_selector.value == "All" else iris.filter(pl.col("Species") == species_selector.value)++ chart = alt.Chart(filtered_data).mark_circle().encode(+ x=alt.X(x_feature.value, title=x_feature.value),+ y=alt.Y(y_feature.value, title=y_feature.value),+ color='Species'+ ).properties(+ title=f"{y_feature.value} vs {x_feature.value}",+ width=500,+ height=400)- plt.title(f"{y_feature.value} vs {x_feature.value}")- plt.gca()++ chart`,])}</example>@@ -242,14 +250,21 @@ export function getAgentPrompt(filename: string) {`import marimo as moimport altair as alt- import pandas as pd+ import polars as pl`,`# Load dataset- cars_df = pd.read_csv('<https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json>')- _chart = alt.Chart(cars_df).mark_point().encode(- x='Horsepower',- y='Miles_per_Gallon',- color='Origin',+ weather = pl.read_csv("https://raw.githubusercontent.com/vega/vega-datasets/refs/heads/main/data/weather.csv")+ weather_dates = weather.with_columns(+ pl.col("date").str.strptime(pl.Date, format="%Y-%m-%d")+ )+ _chart = (+ alt.Chart(weather_dates)+ .mark_point()+ .encode(+ x="date:T",+ y="temp_max",+ color="location",+ ))`,"chart = mo.ui.altair_chart(_chart)\nchart",@@ -278,9 +293,13 @@ export function getAgentPrompt(filename: string) {<example title="SQL with duckdb">${formatCells([- "import marimo as mo\nimport pandas as pd",- `cars_df = pd.read_csv('<https://raw.githubusercontent.com/vega/vega-datasets/master/data/cars.json>')`,- `_df = mo.sql("SELECT * from cars_df WHERE Miles_per_Gallon > 20")`,+ "import marimo as mo\n import polars as pl",+ `weather = pl.read_csv('https://raw.githubusercontent.com/vega/vega-datasets/refs/heads/main/data/weather.csv')`,+ `seattle_weather_df = mo.sql(+ f"""+ SELECT * FROM weather WHERE location = 'Seattle';+ """+ )`,])}</example>`;}diff --git a/marimo/_server/ai/prompts.py b/marimo/_server/ai/prompts.pyindex 44cab42b6f..6f30c432a6 100644--- a/marimo/_server/ai/prompts.py+++ b/marimo/_server/ai/prompts.py@@ -19,7 +19,7 @@ language_rules = {"python": ["For matplotlib: use plt.gca() as the last expression instead of plt.show().","For plotly: return the figure object directly.",- "For altair: return the chart object directly. Add tooltips where appropriate.",+ "For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).","Include proper labels, titles, and color schemes.","Make visualizations interactive where appropriate.","If an import already exists, do not import it again.",@@ -28,6 +28,8 @@ language_rules = {"markdown": [],"sql": ["The SQL must use duckdb syntax.",+ 'SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.',+ "This will automatically display the result in the UI. You do not need to return the dataframe in the cell.",],}@@ -276,6 +278,14 @@ Marimo's reactivity means:## Best Practices+<data_handling>+- Use polars for data manipulation+- Implement proper data validation+- Handle missing values appropriately+- Use efficient data structures+- A variable in the last expression of a cell is automatically displayed as a table+</data_handling>+<ui_elements>- Access UI element values with .value attribute (e.g., slider.value)- Create UI elements in one cell and reference them in later cells@@ -323,7 +333,8 @@ Marimo's reactivity means:<example title="Basic UI with reactivity">import marimo as mo-import matplotlib.pyplot as plt+import altair as alt+import polars as plimport numpy as np# Create a slider and display it@@ -335,12 +346,18 @@ n_points # Display the sliderx = np.random.rand(n_points.value)y = np.random.rand(n_points.value)-plt.figure(figsize=(8, 6))-plt.scatter(x, y, alpha=0.7)-plt.title(f"Scatter plot with {{n_points.value}} points")-plt.xlabel("X axis")-plt.ylabel("Y axis")-plt.gca() # Return the current axes to display the plot+df = pl.DataFrame({{"x": x, "y": y}})++chart = alt.Chart(df).mark_circle(opacity=0.7).encode(+ x=alt.X('x', title='X axis'),+ y=alt.Y('y', title='Y axis')+).properties(+ title=f"Scatter plot with {{n_points.value}} points",+ width=400,+ height=300+)++chart</example>"""for language in language_rules:diff --git a/tests/_server/ai/snapshots/chat_system_prompts.txt b/tests/_server/ai/snapshots/chat_system_prompts.txtindex 1fd7f8758e..6894ab2bc5 100644--- a/tests/_server/ai/snapshots/chat_system_prompts.txt+++ b/tests/_server/ai/snapshots/chat_system_prompts.txt@@ -47,6 +47,14 @@ Marimo's reactivity means:## Best Practices+<data_handling>+- Use polars for data manipulation+- Implement proper data validation+- Handle missing values appropriately+- Use efficient data structures+- A variable in the last expression of a cell is automatically displayed as a table+</data_handling>+<ui_elements>- Access UI element values with .value attribute (e.g., slider.value)- Create UI elements in one cell and reference them in later cells@@ -94,7 +102,8 @@ Marimo's reactivity means:<example title="Basic UI with reactivity">import marimo as mo-import matplotlib.pyplot as plt+import altair as alt+import polars as plimport numpy as np# Create a slider and display it@@ -106,18 +115,24 @@ n_points # Display the sliderx = np.random.rand(n_points.value)y = np.random.rand(n_points.value)-plt.figure(figsize=(8, 6))-plt.scatter(x, y, alpha=0.7)-plt.title(f"Scatter plot with {n_points.value} points")-plt.xlabel("X axis")-plt.ylabel("Y axis")-plt.gca() # Return the current axes to display the plot+df = pl.DataFrame({"x": x, "y": y})++chart = alt.Chart(df).mark_circle(opacity=0.7).encode(+ x=alt.X('x', title='X axis'),+ y=alt.Y('y', title='Y axis')+).properties(+ title=f"Scatter plot with {n_points.value} points",+ width=400,+ height=300+)++chart</example>## Rules for python:1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -125,6 +140,8 @@ plt.gca() # Return the current axes to display the plot## Rules for sql:1. The SQL must use duckdb syntax.+2. SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.+3. This will automatically display the result in the UI. You do not need to return the dataframe in the cell.==================== with custom rules ====================@@ -173,6 +190,14 @@ Marimo's reactivity means:## Best Practices+<data_handling>+- Use polars for data manipulation+- Implement proper data validation+- Handle missing values appropriately+- Use efficient data structures+- A variable in the last expression of a cell is automatically displayed as a table+</data_handling>+<ui_elements>- Access UI element values with .value attribute (e.g., slider.value)- Create UI elements in one cell and reference them in later cells@@ -220,7 +245,8 @@ Marimo's reactivity means:<example title="Basic UI with reactivity">import marimo as mo-import matplotlib.pyplot as plt+import altair as alt+import polars as plimport numpy as np# Create a slider and display it@@ -232,18 +258,24 @@ n_points # Display the sliderx = np.random.rand(n_points.value)y = np.random.rand(n_points.value)-plt.figure(figsize=(8, 6))-plt.scatter(x, y, alpha=0.7)-plt.title(f"Scatter plot with {n_points.value} points")-plt.xlabel("X axis")-plt.ylabel("Y axis")-plt.gca() # Return the current axes to display the plot+df = pl.DataFrame({"x": x, "y": y})++chart = alt.Chart(df).mark_circle(opacity=0.7).encode(+ x=alt.X('x', title='X axis'),+ y=alt.Y('y', title='Y axis')+).properties(+ title=f"Scatter plot with {n_points.value} points",+ width=400,+ height=300+)++chart</example>## Rules for python:1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -251,6 +283,8 @@ plt.gca() # Return the current axes to display the plot## Rules for sql:1. The SQL must use duckdb syntax.+2. SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.+3. This will automatically display the result in the UI. You do not need to return the dataframe in the cell.## Additional rules:Always be polite.@@ -302,6 +336,14 @@ Marimo's reactivity means:## Best Practices+<data_handling>+- Use polars for data manipulation+- Implement proper data validation+- Handle missing values appropriately+- Use efficient data structures+- A variable in the last expression of a cell is automatically displayed as a table+</data_handling>+<ui_elements>- Access UI element values with .value attribute (e.g., slider.value)- Create UI elements in one cell and reference them in later cells@@ -349,7 +391,8 @@ Marimo's reactivity means:<example title="Basic UI with reactivity">import marimo as mo-import matplotlib.pyplot as plt+import altair as alt+import polars as plimport numpy as np# Create a slider and display it@@ -361,18 +404,24 @@ n_points # Display the sliderx = np.random.rand(n_points.value)y = np.random.rand(n_points.value)-plt.figure(figsize=(8, 6))-plt.scatter(x, y, alpha=0.7)-plt.title(f"Scatter plot with {n_points.value} points")-plt.xlabel("X axis")-plt.ylabel("Y axis")-plt.gca() # Return the current axes to display the plot+df = pl.DataFrame({"x": x, "y": y})++chart = alt.Chart(df).mark_circle(opacity=0.7).encode(+ x=alt.X('x', title='X axis'),+ y=alt.Y('y', title='Y axis')+).properties(+ title=f"Scatter plot with {n_points.value} points",+ width=400,+ height=300+)++chart</example>## Rules for python:1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -380,6 +429,8 @@ plt.gca() # Return the current axes to display the plot## Rules for sql:1. The SQL must use duckdb syntax.+2. SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.+3. This will automatically display the result in the UI. You do not need to return the dataframe in the cell.## Available variables from other cells:- variable: `var1`- variable: `var2`@@ -431,6 +482,14 @@ Marimo's reactivity means:## Best Practices+<data_handling>+- Use polars for data manipulation+- Implement proper data validation+- Handle missing values appropriately+- Use efficient data structures+- A variable in the last expression of a cell is automatically displayed as a table+</data_handling>+<ui_elements>- Access UI element values with .value attribute (e.g., slider.value)- Create UI elements in one cell and reference them in later cells@@ -478,7 +537,8 @@ Marimo's reactivity means:<example title="Basic UI with reactivity">import marimo as mo-import matplotlib.pyplot as plt+import altair as alt+import polars as plimport numpy as np# Create a slider and display it@@ -490,18 +550,24 @@ n_points # Display the sliderx = np.random.rand(n_points.value)y = np.random.rand(n_points.value)-plt.figure(figsize=(8, 6))-plt.scatter(x, y, alpha=0.7)-plt.title(f"Scatter plot with {n_points.value} points")-plt.xlabel("X axis")-plt.ylabel("Y axis")-plt.gca() # Return the current axes to display the plot+df = pl.DataFrame({"x": x, "y": y})++chart = alt.Chart(df).mark_circle(opacity=0.7).encode(+ x=alt.X('x', title='X axis'),+ y=alt.Y('y', title='Y axis')+).properties(+ title=f"Scatter plot with {n_points.value} points",+ width=400,+ height=300+)++chart</example>## Rules for python:1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -509,6 +575,8 @@ plt.gca() # Return the current axes to display the plot## Rules for sql:1. The SQL must use duckdb syntax.+2. SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.+3. This will automatically display the result in the UI. You do not need to return the dataframe in the cell.## Available variables from other cells:- variable: `df`@@ -566,6 +634,14 @@ Marimo's reactivity means:## Best Practices+<data_handling>+- Use polars for data manipulation+- Implement proper data validation+- Handle missing values appropriately+- Use efficient data structures+- A variable in the last expression of a cell is automatically displayed as a table+</data_handling>+<ui_elements>- Access UI element values with .value attribute (e.g., slider.value)- Create UI elements in one cell and reference them in later cells@@ -613,7 +689,8 @@ Marimo's reactivity means:<example title="Basic UI with reactivity">import marimo as mo-import matplotlib.pyplot as plt+import altair as alt+import polars as plimport numpy as np# Create a slider and display it@@ -625,18 +702,24 @@ n_points # Display the sliderx = np.random.rand(n_points.value)y = np.random.rand(n_points.value)-plt.figure(figsize=(8, 6))-plt.scatter(x, y, alpha=0.7)-plt.title(f"Scatter plot with {n_points.value} points")-plt.xlabel("X axis")-plt.ylabel("Y axis")-plt.gca() # Return the current axes to display the plot+df = pl.DataFrame({"x": x, "y": y})++chart = alt.Chart(df).mark_circle(opacity=0.7).encode(+ x=alt.X('x', title='X axis'),+ y=alt.Y('y', title='Y axis')+).properties(+ title=f"Scatter plot with {n_points.value} points",+ width=400,+ height=300+)++chart</example>## Rules for python:1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -644,6 +727,8 @@ plt.gca() # Return the current axes to display the plot## Rules for sql:1. The SQL must use duckdb syntax.+2. SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.+3. This will automatically display the result in the UI. You do not need to return the dataframe in the cell.## Available schema:- Table: df_1@@ -709,6 +794,14 @@ Marimo's reactivity means:## Best Practices+<data_handling>+- Use polars for data manipulation+- Implement proper data validation+- Handle missing values appropriately+- Use efficient data structures+- A variable in the last expression of a cell is automatically displayed as a table+</data_handling>+<ui_elements>- Access UI element values with .value attribute (e.g., slider.value)- Create UI elements in one cell and reference them in later cells@@ -756,7 +849,8 @@ Marimo's reactivity means:<example title="Basic UI with reactivity">import marimo as mo-import matplotlib.pyplot as plt+import altair as alt+import polars as plimport numpy as np# Create a slider and display it@@ -768,18 +862,24 @@ n_points # Display the sliderx = np.random.rand(n_points.value)y = np.random.rand(n_points.value)-plt.figure(figsize=(8, 6))-plt.scatter(x, y, alpha=0.7)-plt.title(f"Scatter plot with {n_points.value} points")-plt.xlabel("X axis")-plt.ylabel("Y axis")-plt.gca() # Return the current axes to display the plot+df = pl.DataFrame({"x": x, "y": y})++chart = alt.Chart(df).mark_circle(opacity=0.7).encode(+ x=alt.X('x', title='X axis'),+ y=alt.Y('y', title='Y axis')+).properties(+ title=f"Scatter plot with {n_points.value} points",+ width=400,+ height=300+)++chart</example>## Rules for python:1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -787,6 +887,8 @@ plt.gca() # Return the current axes to display the plot## Rules for sql:1. The SQL must use duckdb syntax.+2. SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.+3. This will automatically display the result in the UI. You do not need to return the dataframe in the cell.<code_from_other_cells>import pandas as pd@@ -840,6 +942,14 @@ Marimo's reactivity means:## Best Practices+<data_handling>+- Use polars for data manipulation+- Implement proper data validation+- Handle missing values appropriately+- Use efficient data structures+- A variable in the last expression of a cell is automatically displayed as a table+</data_handling>+<ui_elements>- Access UI element values with .value attribute (e.g., slider.value)- Create UI elements in one cell and reference them in later cells@@ -887,7 +997,8 @@ Marimo's reactivity means:<example title="Basic UI with reactivity">import marimo as mo-import matplotlib.pyplot as plt+import altair as alt+import polars as plimport numpy as np# Create a slider and display it@@ -899,18 +1010,24 @@ n_points # Display the sliderx = np.random.rand(n_points.value)y = np.random.rand(n_points.value)-plt.figure(figsize=(8, 6))-plt.scatter(x, y, alpha=0.7)-plt.title(f"Scatter plot with {n_points.value} points")-plt.xlabel("X axis")-plt.ylabel("Y axis")-plt.gca() # Return the current axes to display the plot+df = pl.DataFrame({"x": x, "y": y})++chart = alt.Chart(df).mark_circle(opacity=0.7).encode(+ x=alt.X('x', title='X axis'),+ y=alt.Y('y', title='Y axis')+).properties(+ title=f"Scatter plot with {n_points.value} points",+ width=400,+ height=300+)++chart</example>## Rules for python:1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -918,6 +1035,8 @@ plt.gca() # Return the current axes to display the plot## Rules for sql:1. The SQL must use duckdb syntax.+2. SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.+3. This will automatically display the result in the UI. You do not need to return the dataframe in the cell.## Additional rules:Always be polite.diff --git a/tests/_server/ai/snapshots/system_prompts.txt b/tests/_server/ai/snapshots/system_prompts.txtindex fff3e16548..396cb6f08a 100644--- a/tests/_server/ai/snapshots/system_prompts.txt+++ b/tests/_server/ai/snapshots/system_prompts.txt@@ -16,7 +16,7 @@ Immediately start with the following format. Do NOT comment on the code, just ou## Rules for python1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -54,6 +54,8 @@ Immediately start with the following format. Do NOT comment on the code, just ou## Rules for sql1. The SQL must use duckdb syntax.+2. SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.+3. This will automatically display the result in the UI. You do not need to return the dataframe in the cell.Again, just output the code itself.@@ -88,7 +90,7 @@ Immediately start with the following format. Do NOT comment on the code, just ou## Rules for python1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -115,7 +117,7 @@ Immediately start with the following format. Do NOT comment on the code, just ou## Rules for python1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -156,7 +158,7 @@ Immediately start with the following format. Do NOT comment on the code, just ou## Rules for python1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -193,7 +195,7 @@ print('Hello, world!')## Rules for python1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -230,7 +232,7 @@ print('Hello, world!')## Rules for python1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -266,7 +268,7 @@ pl.DataFrame()## Rules for python1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -295,7 +297,7 @@ Immediately start with the following format. Do NOT comment on the code, just ou## Rules for python1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -340,7 +342,7 @@ Separate logic into multiple cells to keep the code organized and readable.## Rules for python:1. For matplotlib: use plt.gca() as the last expression instead of plt.show().2. For plotly: return the figure object directly.-3. For altair: return the chart object directly. Add tooltips where appropriate.+3. For altair: return the chart object directly. Add tooltips where appropriate. You can pass polars dataframes directly to altair (e.g., alt.Chart(df)).4. Include proper labels, titles, and color schemes.5. Make visualizations interactive where appropriate.6. If an import already exists, do not import it again.@@ -348,6 +350,8 @@ Separate logic into multiple cells to keep the code organized and readable.## Rules for sql:1. The SQL must use duckdb syntax.+2. SQL cells start with df = mo.sql(f"""<your query>""") for DuckDB, or df = mo.sql(f"""<your query>""", engine=engine) for other SQL engines.+3. This will automatically display the result in the UI. You do not need to return the dataframe in the cell.## Available variables from other cells:- variable: `df`