Listen to the podcast
Generative AI Scripting
Prompting is Coding
Programmatically assemble prompts for LLMs using JavaScript. Orchestrate LLMs, tools, and data in a single script.
- JavaScript toolbox to work with prompts
- Abstraction to make it easy and productive
- Seamless Visual Studio Code integration
Hello world
Say to you want to create an LLM script that generates a ‘hello world’ poem. You can write the following script:
$`Write a 'hello world' poem.`
The $
function is a template tag that creates a prompt. The prompt is then sent to the LLM (you configured), which generates the poem.
Let’s make it more interesting by adding files, data, and structured output. Say you want to include a file in the prompt, and then save the output in a file. You can write the following script:
// read filesconst file = await workspace.readText("data.txt")// include the file content in the prompt in a context-friendly waydef("DATA", file)// the task$`Analyze DATA and extract data in JSON in data.json.`
The def
function includes the content of the file, and optimizes it if necessary for the target LLM. GenAIScript script also parses the LLM output
and will extract the data.json
file automatically.
Next steps
Install the extension
Install the Visual Studio Code Extension to get started.
Configure your LLMs
Configure the secrets to access your LLMs.
Write your first script
Follow Getting Started to write your first script.
Read the docs
Learn more about GenAIScript in the Scripting Reference.

Features
GenAIScript brings essential LLM prompt tooling into a cohesive scripting environment.
Stylized JavaScript
Minimal syntax to build prompts using JavaScript or TypeScript.
$`Summarize ${env.files}. Today is ${new Date()}.`
Fast Development Loop
Edit, Debug, Run, Test your scripts in Visual Studio Code or with a command line.

LLM Tools
Register JavaScript functions as LLM tools (with fallback for models that don’t support tools).
defTool("weather", "live weather", { city: "Paris" }, // schema async ({ city }) => // callback { ... "sunny" })
or use @agentic tools
import { WeatherClient } from "@agentic/weather"defTool(new WeatherClient())
Model Context Provider Client
Use tools exposed in MCP Servers
defTool({ memory: { command: "npx", args: ["-y", "@modelcontextprotocol/server-memory"], },})
LLM Agents
Combine tools and inline prompts into an agent.
defAgent( "git", "Agent that answer git questions for the current repo", "You are a helpful expert in using git.", { tools: ["git"] })
script({ tools: "agent" })
$`Do a statistical analysis of the last commits`
Reuse and Share Scripts
Scripts are files! They can be versioned, shared, forked, …
Directorygenaisrc
- my-script.genai.mjs
- another-great-script.genai.mjs
Data Schemas
Define, validate, repair data using schemas.
const data = defSchema("MY_DATA", { type: "array", items: { ... }, })$`Extract data from files using ${data} schema.`
Ingest text from PDFs, DOCX, ...
Ingest tables from CSV, XLSX, ..
Manipulate tabular data from CSV, XLSX, …
// automatically convert to textdef("DATA", env.files, { endsWith: ".csv", // take top 100 rows sliceHead: 100,})// or parse to JavaScript object arrayconst rows = await parsers.CSV(env.files[0])// render as markdown tabledefData("ROWS", rows, { sliceHead: 100 })
Speech To Text
Images
Include images in prompts, we’ll crop/resize/resize then for you.
defImages(images, { autoCrop: true, details: "low" })
Videos
Extract frames from videos using timestamps or even transcripts.
const frames = await ffmpeg.extractFrames("...", { count: 10 })defImages(frames, { details: "low" })
Generate Files
Extract files and diff from the LLM output. Preview changes in Refactoring UI.
$`Save the result in poem.txt.`
FILE ./poem.txt```txtThe quick brown fox jumps over the lazy dog.```
- poem.txt extracted by genaiscript
File search
Grep or fuzz search files
const { files } = await workspace.grep(/[a-z][a-z0-9]+/, { globs: "*.md" })
Web search
Web search using Bing or Tavily.
const pages = await retreival.webSearch("what are the latest news about AI?")
Browser automation
Browse and scrape the web with Playwright.
const page = await host.browse("https://...")const table = await page.locator("table[...]").innerHTML()def("TABLE", await HTML.convertToMarkdown(table))
RAG built-in
const { files } = await retrieval.vectorSearch("cats", "**/*.md")
Safety First!
GenAIScript provides built-in Responsible AI system prompts and Azure Content Safety supports to validate content safety.
script({ ..., systemSafety: "default", contentSafety: "azure" // use azure content safety})
const safety = await host.contentSafety()const res = await safety.detectPromptInjection(env.vars.input)
GitHub Models and GitHub Copilot
Run models through GitHub using GitHub Models or GitHub Copilot.
script({ ..., model: "github:gpt-4o" })
Azure, Google, Anthropic, Amazon, Alibaba, ...
Run models from Azure, Google, Anthropic, Alibaba, and more. See Configuration.
script({ ..., model: "google:gemini-1.5-flash"})
Local Models
Run your scripts with Open Source models, like Phi-3, using Ollama, LocalAI…
script({ ..., model: "ollama:phi3" })
Code Interpreter
Let the LLM run code in a sandboxed execution environment.
script({ tools: ["python_code_interpreter"] })
Containers
Run code in Docker containers.
const c = await host.container({ image: "python:alpine",})const res = await c.exec("python --version")
LLM Composition
Run LLMs to build your LLM prompts.
// summarize each files individuallyfor (const file of env.files) { const { text } = await runPrompt((_) => { _.def("FILE", file) _.$`Summarize the FILE.` }) // use result in main prompt def("SUMMARY", text)}// use summary$`Summarize all the summaries.`
Classify
Classify text, images or a mix of all.
const joke = await classify( "Why did the chicken cross the roard? To fry in the sun.", { yes: "funny", no: "not funny", })
Prompty
Run or convert Prompty files using GenAIScript.
---name: poem---
system:Write a short poem aboutuser:{{something}}.
importTemplate("poem.prompty", { something: "code " })
Pluggable Secret Scanning
Scan your chats for secrets using secret scanning.
{ "secretPatterns": { ..., "OpenAI API Key": "sk-[A-Za-z0-9]{32,48}" }}
Automate with CLI
Automate using the CLI, integrate reports in your CI/CD pipeline.
npx genaiscript run tlaplus-linter "*.tla"
Pull Request Reviews
Integrate into your Pull Requests checks through comments, reviews or description updates. Supports GitHub Actions and Azure DevOps pipelines.
npx genaiscript ... --pull-request-reviews
Tests and Evals
Build reliable prompts using tests and evals powered by promptfoo.
script({ ..., tests: { files: "penguins.csv", rubric: "is a data analysis report", facts: "The data refers about penguin population in Antartica.",}})

Case Studies
Tales from the real world using GenAIScript.
Samples
Fully fledged scripts ready to use.
Guides
A cookbook full of recipes to make you a genius scripter.
Agents
Builtin Agents
LLM friendly docs
If you are an LLM crawler, fetch https://microsoft.github.io/genaiscript/.well-known/llms.txt for an documentation map
or add the .md
suffix to any documentation URLs to get a raw markdown content.
For example, https://microsoft.github.io/genaiscript/guides/prompt-as-code.md (note the .md extension)