msh ai new
Generate a new .msh asset from natural language description.
Usage
msh ai new [--name <name>] [--apply] [--path <path>]
Description
Prompts user for a natural language description and generates a complete .msh file with:
- Ingest block (appropriate type based on description)
- Transform block with SQL
- Tests
- Contract block (if needed)
Options
--name <name>: Suggested asset ID/name--apply: Write the generated asset to disk automatically--path <path>: Path to save the new.mshfile (if--applyis set)
Examples
Generate Asset (Preview Only)
msh ai new --name customer_revenue
Interactive Flow:
-
Prompts for description:
Describe the asset you want to create:
> Create an asset that ingests customer data from a REST API
> and calculates monthly revenue per customer -
Generates
.mshfile using AI -
Shows preview:
name: customer_revenue
description: Calculates monthly revenue per customer
ingest:
type: rest_api
endpoint: https://api.example.com/customers
resource: customers
transform: |
SELECT
customer_id,
DATE_TRUNC('month', order_date) as month,
SUM(amount) as monthly_revenue
FROM {{ source }}
GROUP BY customer_id, DATE_TRUNC('month', order_date)
tests:
- assert: "monthly_revenue > 0"
- unique: [customer_id, month] -
Validates safety (blocks dangerous operations)
-
Saves file if
--applyis set
Generate and Save Automatically
msh ai new --name customer_revenue --apply
Generates the asset and saves it automatically without prompting.
Generate and Save to Specific Path
msh ai new --name customer_revenue --apply --path assets/customer_revenue.msh
Generates the asset and saves it to the specified path.
Description Examples
REST API Ingestion
Create an asset that ingests customer data from a REST API endpoint
https://api.example.com/customers and calculates total revenue per customer
SQL Database Ingestion
Create an asset that reads from the orders table in PostgreSQL and
calculates monthly revenue grouped by customer and month
Transformation Only
Create an asset that transforms the stg_orders staging table to calculate
monthly revenue per customer, joining with customer information
Safety Validation
The safety layer blocks dangerous operations:
DROP TABLETRUNCATE TABLEDELETE FROMALTER TABLE ... DROP COLUMN
If the generated asset contains dangerous operations, generation is blocked.
Prerequisites
-
AI Configuration: Must configure AI provider first
msh config ai --provider openai --model gpt-4 --api-key env:OPENAI_API_KEY -
Manifest: Generate manifest before using AI commands
msh manifest -
Project Context: AI uses project context (sources, glossary) to generate better assets
Refining Generated Assets
After generation, you can:
-
Review the asset: Check the generated code
msh ai review assets/customer_revenue.msh -
Explain the asset: Understand what it does
msh ai explain assets/customer_revenue.msh -
Fix issues: Let AI suggest fixes
msh ai fix assets/customer_revenue.msh --apply -
Improve tests: Generate better tests
msh ai tests assets/customer_revenue.msh --apply
Best Practices
- Be specific: Provide detailed descriptions for better results
- Review before applying: Always review generated code before
--apply - Use glossary terms: Reference glossary terms in descriptions for better alignment
- Iterate: Use
msh ai fixandmsh ai reviewto refine generated assets
Related Commands
msh ai review- Review generated assetmsh ai fix- Fix issues in generated assetmsh ai tests- Improve tests