# Overview

> Learn how to use and customize GenAIScript templates for efficient AI prompt expansion.

GenAIScript supports multiple file formats for creating AI prompt templates:

* **JavaScript** files named as `*.genai.mjs` or `*.genai.js`
* **TypeScript** files named as `*.genai.mts`
* **Markdown** files named as `*.genai.md` for simpler, text-based prompts

shorten.genai.mjs

```js
script({
  title: "Shorten", // displayed in UI and Copilot Chat
  // also displayed but grayed out:
  description:
    "A prompt that shrinks the size of text without losing meaning",
});


// but the variable is appropriately delimited
const file = def("FILE", env.files);


// this appends text to the prompt
$`Shorten ${file}. Limit changes to minimum.`;
```

The same script can also be written as a markdown file:

shorten.genai.md

```markdown
---
title: "Shorten"
description: "A prompt that shrinks the size of text without losing meaning"
---
Shorten the provided text. Limit changes to minimum while preserving meaning.
```

## Script files

[Section titled “Script files”](#script-files)

* GenAIScript will detect any file matching `*.genai.mjs`, `*.genai.js`, `*.genai.mts`, or `*.genai.md` in your workspace.
* GenAIScript files can be placed anywhere in your workspace; but the extension will place them in a `genaisrc` folder by default.
* `.genai.mjs` use module JavaScript syntax and support [imports](/genaiscript/reference/scripts/imports).
* `.genai.js` are eval-ed and do not support imports.
* `.genai.mts` are [TypeScript module files](/genaiscript/reference/scripts/typescript) and support [imports](/genaiscript/reference/scripts/imports), including dynamic imports of other TypeScript files.
* `.genai.md` are [Markdown script files](/genaiscript/reference/scripts/markdown-scripts) with YAML frontmatter for configuration.

- /genaisrc

  * jsconfig.json // TypeScript compiler configuration
  * genaiscript.d.ts // TypeScript definitions
  * myscript.genai.mjs // JavaScript script
  * analyze.genai.mts // TypeScript script
  * summarize.genai.md // Markdown script
  * …

* `system.*.genai.mjs` are considered [system prompt templates](/genaiscript/reference/scripts/system) and are unlisted by default.

## Topics

[Section titled “Topics”](#topics)

[Map-Reduce ](/genaiscript/reference/scripts/mapreduce)Learn how to use the map and reduce functions in GenaScript for efficient data processing

[Metadata ](/genaiscript/reference/scripts/metadata)Learn how to configure script metadata to enhance functionality and user experience in GenAIScript.

[Prompt ($) ](/genaiscript/reference/scripts/prompt)Learn how to use the tagged template literal for dynamic prompt generation in GenAI scripts.

[Context (env+def) ](/genaiscript/reference/scripts/context)Detailed documentation on the script execution context and environment variables in GenAIScript.

[Variables ](/genaiscript/reference/scripts/variables)Discover how to utilize and customize script variables for dynamic scripting capabilities with env.vars.

[File Output ](/genaiscript/reference/scripts/file-output)Learn how to declare and manage script-generated file outputs with defFileOutput function.

[Tools ](/genaiscript/reference/scripts/tools)Learn how to define and use tools within GenAIScript to enhance answer assembly with custom logic and CLI tools.

[Model Context Protocol Tools ](/genaiscript/reference/scripts/mcp-tools)Learn how to configure and securely use Model Context Protocol (MCP) tools and servers, including tool output validation, secret detection, and security best practices for AI scripting.

[Model Context Protocol Server ](/genaiscript/reference/scripts/mcp-server)Turns scripts into Model Context Protocol Tools

[Model Context Protocol Clients ](/genaiscript/reference/scripts/mcp-clients)MCP Clients

[Data Schemas ](/genaiscript/reference/scripts/schemas)Learn how to define and use data schemas for structured output in JSON/YAML with LLM, including validation and repair techniques.

[Agents ](/genaiscript/reference/scripts/agents)An Agent is a tool that queries an LLM, equipped with other tools, to accomplish tasks.

[DOCX ](/genaiscript/reference/scripts/docx)Learn how to parse and extract text from DOCX files for text analysis and processing.

[PDF ](/genaiscript/reference/scripts/pdf)Learn how to extract text from PDF files for prompt generation using GenAIScript's PDF parsing capabilities.

[XML ](/genaiscript/reference/scripts/xml)Discover how to automatically parse XML files and convert them to JSON objects, enabling efficient data handling, RSS feed parsing, and file processing.

[Markdown ](/genaiscript/reference/scripts/md)Enhance your markdown capabilities with MD class helpers for parsing and managing frontmatter efficiently.

[Images ](/genaiscript/reference/scripts/images)Learn how to add images to prompts for AI models supporting visual inputs, including image formats and usage.

[Inline prompts ](/genaiscript/reference/scripts/inline-prompts)Learn how to use inline prompts with runPrompt function for inner LLM invocations in scripting.

[Retrieval ](/genaiscript/reference/scripts/retrieval)Learn how to use GenAIScript's retrieval utilities for content search and prompt augmentation with RAG techniques.

[Secret Scanning ](/genaiscript/reference/scripts/secret-scanning)Learn how to detect and prevent sensitive information leaks in your codebase using automated secret scanning, customizable patterns, and configuration options.

[System Prompts ](/genaiscript/reference/scripts/system)Learn how to utilize system prompts to enhance script execution in GenAIScript.

[Vector Search ](/genaiscript/reference/scripts/vector-search)Learn how to use the retrieval.vectorSearch function to index files with embeddings for efficient similarity search in vector databases.

[Videos as Inputs ](/genaiscript/reference/scripts/videos)How to use the Video in scripts

[Annotations ](/genaiscript/reference/scripts/annotations)Learn how to add annotations such as errors, warnings, or notes to LLM output for integration with VSCode or CI environments.

[File Merge ](/genaiscript/reference/scripts/file-merge)Customize file merging in scripts with defFileMerge function to handle different file formats and merging strategies.

[Tests / Evals ](/genaiscript/reference/scripts/tests)Learn how to execute and evaluate LLM output quality with promptfoo, a tool designed for testing language model outputs.

[Red Team ](/genaiscript/reference/scripts/redteam)Learn how to implement LLM red teaming to identify vulnerabilities in AI systems using PromptFoo, including configuration, plugins like OWASP Top 10, and effective strategies for adversarial testing.

[Custom Output ](/genaiscript/reference/scripts/custom-output)Learn how to use the defOutputProcessor function for custom file processing in script generation.

[Parsers ](/genaiscript/reference/scripts/parsers)Comprehensive guide on various data format parsers including JSON5, YAML, TOML, CSV, PDF, DOCX, and token estimation for LLM.

[Structured Outputs ](/genaiscript/reference/scripts/structured-output)Utilize structured output in GenAIScript to generate JSON data with schema validation for precise and reliable data structuring.

[Files ](/genaiscript/reference/scripts/files)Learn how to perform secure file system operations using the workspace object in your scripts.

[Fetch ](/genaiscript/reference/scripts/fetch)Learn how to use fetch and fetchText in scripts to make HTTP requests and handle text responses.

[Cache ](/genaiscript/reference/scripts/cache)Learn how LLM requests are cached in scripts to optimize performance and how to manage cache settings.

[Cancel ](/genaiscript/reference/scripts/cancel)Learn how to immediately stop script execution with the cancel function in your automation scripts.

[Diff ](/genaiscript/reference/scripts/diff)Learn how to create and interpret file diffs within GenAIScript.

[Markdown Scripts ](/genaiscript/reference/scripts/markdown-scripts)Learn how to write GenAIScript templates using Markdown syntax

[Output Builder ](/genaiscript/reference/scripts/output-builder)Learn how to build a markdown output for your script execution

[TypeScript ](/genaiscript/reference/scripts/typescript)Learn how to use TypeScript for better tooling and scalability in your GenAIScript projects.

[Web Search ](/genaiscript/reference/scripts/web-search)Execute web searches with the Bing API using retrieval.webSearch in scripts.

[Secrets ](/genaiscript/reference/scripts/secrets)Learn how to securely access and manage environment secrets in your scripts with env.secrets object.

[YAML ](/genaiscript/reference/scripts/yaml)Learn how to use YAML for data serialization, configuration, and parsing in LLM with defData, YAML class, and JSON schema validation.

[CSV ](/genaiscript/reference/scripts/csv)Learn how to parse and stringify CSV data using the CSV class in scripting.

[INI ](/genaiscript/reference/scripts/ini)Learn how to parse and stringify INI files in GenAIScript with the INI class, including methods and usage examples.

[XLSX ](/genaiscript/reference/scripts/xlsx)Learn how to parse and stringify Excel XLSX files with ease using our tools.

[HTML ](/genaiscript/reference/scripts/html)Learn how to use HTML parsing functions in GenAIScript for effective content manipulation and data extraction.

[ast-grep ](/genaiscript/reference/scripts/ast-grep)Search for patterns in the AST of a script

[Choices ](/genaiscript/reference/scripts/choices)Specify a list of preferred token choices for a script.

[Containers ](/genaiscript/reference/scripts/container)Learn how to use containers for secure and isolated execution of untrusted code with Docker in software development.

[Content Safety ](/genaiscript/reference/scripts/content-safety)Learn about the built-in safety features, system prompts, and Azure AI Content Safety services to protect language model applications from harmful content, prompt injections, and prompt leaks.

[Imports ](/genaiscript/reference/scripts/imports)Learn how to enable module imports in GenAI scripts by converting them to .mjs format and using static or dynamic imports.

[Logging ](/genaiscript/reference/scripts/logging)Logging mechanism for scripts.

[Diagrams ](/genaiscript/reference/scripts/diagrams)Create diagrams and charts within markdown using GenAIScript and the mermaid extension for visual representation of data and processes.

[Browser Automation ](/genaiscript/reference/scripts/browser)Discover how GenAIScript integrates with Playwright for web scraping and browser automation tasks.

[Audio Transcription ](/genaiscript/reference/scripts/transcription)Describe how to transcribe an audio/video file

[Image Generation ](/genaiscript/reference/scripts/image-generation)Use image generation like OpenAI DALL-E Stable Diffusion to generate images from text.

[Chat Participants ](/genaiscript/reference/scripts/chat-participants)Create multi-turn chats or simulate conversations with multiple chat participants

[Concurrency ](/genaiscript/reference/scripts/concurrency)How to run multiple prompts concurrently

[GitHub ](/genaiscript/reference/scripts/github)Support for querying GitHub

[Import Template ](/genaiscript/reference/scripts/import-template)Learn how to import prompt templates into GenAIScript using \`importTemplate\` with support for mustache variable interpolation and file globs.

[LogProbs ](/genaiscript/reference/scripts/logprobs)Learn how to use logprobs to diagnose the performance of your scripts

[Parameters Schema ](/genaiscript/reference/scripts/parameters)Parameters schema are used to define signatures of scripts, tools.

[Git ](/genaiscript/reference/scripts/git)Git utilities for repository operations

[Markdown Script Include ](/genaiscript/reference/scripts/markdown-include)Learn how to include external files in markdown scripts using the @include directive

[Prompty ](/genaiscript/reference/scripts/prompty)Learn about the .prompty file format for parameterized prompts and its integration with GenAIScript for AI scripting.

[Git Worktrees ](/genaiscript/reference/scripts/git-worktrees)Git worktree support for managing multiple working directories

[Model Aliases ](/genaiscript/reference/scripts/model-aliases)Give friendly names to models

[Pyodide ](/genaiscript/reference/scripts/pyodide)Run Python code in the JavaScript environment using Pyodide.

[Tokenizers ](/genaiscript/reference/scripts/tokenizers)Tokenizers are used to split text into tokens.

[Prompt Caching ](/genaiscript/reference/scripts/prompt-caching)Learn how prompt caching can reduce processing time and costs for repetitive LLM prompts, with details on configuration and provider support including OpenAI and Anthropic.

[Microsoft Teams ](/genaiscript/reference/scripts/teams)Learn how to use the Microsoft Teams integration in your scripts.

[User Input ](/genaiscript/reference/scripts/user-input)How to get user input in a script

[Fence Formats ](/genaiscript/reference/scripts/fence-formats)Explore various fence formats supported by GenAIScript for optimal LLM input text formatting.

[Notebook ](/genaiscript/reference/scripts/notebook)Explore the features of the Markdown Notebook for authoring documentation with script snippets and inline results.

[Reasoning Models ](/genaiscript/reference/scripts/reasoning-models)Specific information about OpenAI reasoning models.

[Response Priming ](/genaiscript/reference/scripts/response-priming)Learn how to prime LLM responses with specific syntax or format using the writeText function in scripts.

[Stored Completions ](/genaiscript/reference/scripts/stored-completions)Metadata for the script