AI Code Generation
marimo includes AI-powered features to help you create notebooks faster and more efficiently. Generate entire notebooks from natural language prompts or use AI assistance within your existing notebooks.AI features in marimo use state-of-the-art language models to understand your intent and generate working Python code.
Text-to-Notebook
The Text-to-Notebook feature allows you to generate complete marimo notebooks from simple text descriptions.How It Works
AI generates the code
marimo’s AI processes your prompt and generates a complete notebook with cells, code, and visualizations.
Using Text-to-Notebook
You can generate notebooks from the command line:Example Prompts
Here are some example prompts that work well:How AI Generation Works
When you use the text-to-notebook feature:- Your prompt is sent to marimo’s AI API at
https://ai.marimo.app/ - The API uses OpenAI/Anthropic models to convert your prompt into a notebook
- Your prompt is securely stored for caching purposes (fast response times)
- No personal data beyond the prompt itself is collected
Terms of Service
When you first use the text-to-notebook feature, you’ll see:AI Chat Integration
marimo also supports AI chat interfaces through themo.ui.chat() component.
Creating a Chat Interface
Chat Configuration
Configure the chat model with various options:Chat Messages
Work with chat messages programmatically:Configuring AI Providers
marimo supports multiple AI providers. Configure them through environment variables or notebook settings.OpenAI
Anthropic
Other Providers
marimo uses PydanticAI under the hood, which supports:- OpenAI
- Anthropic
- Google Gemini
- Groq
- Mistral
- Custom providers
Using custom providers
Using custom providers
You can configure custom AI providers by implementing the appropriate interface. See the PydanticAI documentation for details.
Zero-Shot Notebook Generation
The text-to-notebook feature uses zero-shot generation, meaning:- No examples needed - just describe what you want
- Works with various domains: data analysis, ML, visualization, web apps
- Generates complete, runnable notebooks
- Includes imports, data loading, analysis, and visualization
What Gets Generated
A typical generated notebook includes:Best Practices
Be Specific
Provide clear, detailed descriptions of what you want the notebook to do.
Include Context
Mention data sources, expected outputs, and any specific libraries to use.
Iterate
Generated notebooks are starting points - review and refine the code.
Test Thoroughly
Always test generated code with your actual data before using in production.
Writing Good Prompts
Good prompt structure
Good prompt structure
A good prompt includes:
- Clear objective: What should the notebook accomplish?
- Data description: What kind of data will be used?
- Expected outputs: What visualizations or results do you want?
- Specific requirements: Any libraries, methods, or constraints?
Troubleshooting
Generation fails or times out
Generation fails or times out
- Check your internet connection
- Try a simpler prompt first
- Make sure you’ve accepted the terms of service
- Verify that the marimo AI API is accessible
Generated code doesn't work
Generated code doesn't work
- Review the generated code for obvious errors
- Make sure required libraries are installed
- Try regenerating with a more specific prompt
- Manually adjust the code as needed
Want to revoke AI access
Want to revoke AI access
Edit
~/.marimo/state.toml and remove or modify the accepted_text_to_notebook_terms_at field.Privacy and Security
What marimo collects:- Your text prompts
- Generated notebook code (for caching)
- Personal identifying information
- Your notebook data
- API keys or credentials
- File contents from your system