mlld
Version:
mlld: a modular prompt scripting language
333 lines (242 loc) • 8.84 kB
Markdown
mlld is a modular prompt scripting language, bringing software engineering to LLM workflows: modularity, versioning, and reproducibility.
I still consider it 'early', but this isn't a slapped together idea. I've been working on it nearly every single day for 7 months straight. It has tools for writing tests and a public/private module system.
[](https://mlld.ai/llms.txt)
```bash
npm install -g mlld
```
or just run it with `npx mlld`
For CI/CD and serverless environments, use `npx mlldx` for ephemeral execution.
- makes context and prompt engineering multiplayer and git-versionable
- turns markdown documents into subsection-addressable modules
- public and private modules for prompts and processing
- complex chaining and filtering of LLM calls
- abstract out processing complexity in modules, keep things readable
- get a better handle on the explosion of llm workflow tool cruft
Use mlld to create a daily standup update based on your recent activity:
```mlld
/var @commits = run {git log --since="yesterday"}
/var @prs = run {gh pr list --json title,url,createdAt}
/exe @claude(request) = run {claude -p "@request"}
/exe @formatPRs(items) = js {
return items.map(pr => `- PR: ${pr.title} (${pr.url})`).join('\n');
}
/var @prompt = `
Write a standup update in markdown summarizing the work I did
yesterday based on the following commits and PRs.
@commits
@formatPRs(@prs)
`
/show @claude(@prompt)
```
```bash
npm install -g mlld
```
**Context engineering** - Compose prompts from multiple sources instead of mega-prompts or lots of legwork
**Pipelines** - Chain LLM calls with `|` for iterative refinement
**Logical routing** - Use operators and conditions to route data and actions dynamically
**Modules** - Share and reuse workflows like npm packages
**Reproducible** - Lock files ensure workflows run identically over time
**CI-ready** - `mlldx` runs without filesystem persistence for serverless/containers
```mlld
/var @name = "Alice"
/show `Hello @name!`
/run {echo "System: @name logged in"}
```
Only `/show`, `/run`, and `/output` produce output. Everything else sets up state.
```mlld
/import { codeStyle } from @company/standards
/var @currentPR = run {gh pr view --json body}
/var @prompt = `
Review this PR against our style guide:
Style: @codeStyle
PR: @currentPR
`
/run {claude -p "@prompt"}
```
```mlld
/exe @checkFacts(text) = run "claude -p 'Verify facts in: @text'"
/exe @improveClarity(text) = run "claude -p 'Rewrite for clarity: @text'"
/exe @addExamples(text) = run "claude -p 'Add examples to: @text'"
/var @answer = run {claude -p "@question"} | @checkFacts | @improveClarity | @addExamples
```
```mlld
/var @files = ["report.md", "summary.md", "notes.md"]
/for @file in @files => /show `Processing: @file`
/var @scores = [85, 92, 78, 95]
/var @grades = for @score in @scores => when: [
@score >= 90 => "A"
@score >= 80 => "B"
true => "C"
]
/var @models = ["claude-3", "gpt-4", "gemini"]
/var @prompts = ["Explain X", "Compare Y", "Design Z"]
/exe @query(model, prompt) = run "@model -p '@prompt'"
/var @results = foreach @query(@models, @prompts) << 9 results
```
```mlld
/import { formatDate, validate } from @alice/utils
/import { analyze } from @company/tools
/var @report = @analyze(@data) | @validate
```
```bash
mlld setup
```
Now `@company/prompts` resolves directly from your private GitHub repository.
```bash
mlld init my-module.mld.md
mlld publish my-module.mld.md
```
mlld provides conditional logic with operators and routing capabilities.
```mlld
/var @canDeploy = @isProd && @testsPass && !@hasErrors
/var @userLevel = @score > 90 ? "expert" : "beginner"
/when @branch == "main" && @ci == "passing" => @deploy()
/when @user.role != "admin" => /show "Access denied"
```
Route actions based on complex conditions:
```mlld
/when @request first: [
@method == "GET" && @path == "/users" => @listUsers()
@method == "POST" && @path == "/users" => @createUser()
@method == "DELETE" => @deleteResource()
]
/when @features: [
@hasAuth => @authModule = "enabled"
@hasChat => @loadChat()
@hasVideo => /import { video } from @company/video
]
```
Use `when:` to create conditional values:
```mlld
/var @greeting = when: [
@time < 12 => "Good morning"
@time < 18 => "Good afternoon"
true => "Good evening"
]
/exe @processData(type, data) = when: [
@type == "json" => @jsonHandler(@data)
@type == "xml" => @xmlHandler(@data)
true => @genericHandler(@data)
]
```
Read more about [/when](docs/slash/when.md)
```mlld
/import { styleGuide } from @company/standards
/import { githubContext } from @tools/github
/var @changes = run {git diff main..HEAD}
/var @context = @githubContext()
/exe @review(perspective) = run {
claude -p "As a @perspective, review: @changes with context: @context"
}
/var @reviews = foreach @review([
"security expert",
"performance engineer",
"API designer"
])
/output @reviews to "review.md"
```
```mlld
/var @question = "What are the tradeoffs of microservices?"
/exe @ask(model) = run "@model -p '@question'"
/var @responses = foreach @ask(["claude", "gpt-4", "gemini"])
/var @consensus = run {
claude -p "Synthesize these viewpoints: @responses"
}
/show @consensus
```
```bash
mlld file.mld
mlld file.mld --stdout
mlld file.mld --format xml
mlld file.mld --watch
mlld file.mld --env .env.local
```
```bash
mlld init
mlld init utils
mlld auth login
mlld publish my-module.mld.md
mlld publish --private
```
```bash
mlld setup
mlld alias --name lib --path ./src/lib
mlld alias --name shared --path ../shared --global
mlld env allow GITHUB_TOKEN API_KEY
mlld env list
```
```bash
mlld run
mlld run analyze-pr
mlld run data/process
```
```bash
mlld test
mlld test array
mlld test --env custom.env
mlld clean @mlld/env
mlld clean --all
mlld clean --registry
mlld add-needs my-module.mld
```
```bash
mlldx script.mld
mlldx script.mld --env prod.env
npx mlldx@latest ci-task.mld
mlldx github-action.mld
mlldx vercel-function.mld
docker run -it node:18 npx mlldx@latest /scripts/task.mld
```
- [Documentation](docs/)
- [LLM Reference](llms.txt) - Give this to your AI assistant
- [Examples](examples/)