Prompty

repository·main·Indexed 22 days ago

https://github.com/microsoft/prompty

A markdown-based file format for LLM prompts that allows developers to write prompts once and run them across different environments, including Python, TypeScript, and .NET. It uses .prompty files consisting of YAML frontmatter for configuration and a markdown body for prompt templates supporting Jinja2 and Mustache. Prompty provides SDKs for various providers such as OpenAI, Anthropic, and Microsoft Foundry, as well as a VS Code extension for creating, previewing, and debugging prompts.

Tokens
210.8K
Snippets
512
Records
1K
Agent score
78%

What's inside Prompty

  1. What is Prompty?

    main

    Prompty is a Microsoft project that provides a specialized asset class and format for LLM (Large Language Model) prompts. It is designed to improve observability, understandability, and portability for developers.

    Prompty aims to accelerate the developer inner loop of prompt engineering and prompt source management across different languages and platforms, helping developers build, test, and deploy generative AI applications more efficiently.

  2. Overview of Prompty

    main

    Prompty is an asset class and file format for Large Language Model (LLM) prompts. It is designed to improve observability, understandability, and portability during the prompt engineering process, specifically aiming to accelerate the developer inner loop.

    Key features include:

    • .prompty support: Language support and syntax highlighting for the prompt format.
    • Prompt Playground: Commands to preview and run prompts directly within VS Code.
    • Connections Management: A sidebar to manage endpoints for OpenAI, Microsoft Foundry, and Anthropic.
    • Trace Viewing: Ability to view execution traces using .tracy files.
    • Runtime Integration: Seamless integration with Prompty runtime packages.
  3. Overview of the Prompty VS Code Extension

    main

    The Prompty VS Code extension is the primary tool for authoring, running, and debugging .prompty files. It features a built-in TypeScript runtime, meaning no Python installation is required to use it.

    Key capabilities include:

    • Language support: TextMate grammar and a language server providing validation, completion, hover, semantic tokens, and document symbols.
    • Connections: Secure management of OpenAI, Anthropic, and Microsoft Foundry connections using secure secret storage.
    • Execution: Ability to run prompts, preview rendered output, and use an interactive chat mode for thread-based prompts.
    • Traces: Support for the .tracy file format with a React-based trace viewer.
    • Extensibility: An API for other extensions to register providers, executors, and processors.
  4. What is Prompty?

    main

    Prompty is a markdown-based file format for LLM prompts. It uses a single .prompty file to pair YAML frontmatter with a markdown prompt body, making prompts portable and executable across Python, TypeScript, and VS Code.

    In a .prompty file, you can define:

    • Model configuration and connection details.
    • Input schema including types and defaults.
    • Tool definitions (supporting function calling, MCP, and OpenAPI).
    • Templates using Jinja2 or Mustache for variable expansion.
  5. Overview of Prompty Runtime APIs

    main

    The Prompty runtime provides a set of public APIs for managing the lifecycle of a prompt. These APIs allow you to load, prepare, run, and extend prompt execution. The core functional areas include:

    • Pipeline Functions: Managing the flow from loading a .prompty file to execution (load, render, parse, prepare, run, invoke, process).
    • Agentic Capabilities: Handling multi-turn interactions (turn), tool dispatching, and agent-mode error handling.
    • Tool Calling: Registering and dispatching tool calls with specific handlers and bindings.
    • Connections: Using the Connection Registry to map named clients and configurations to connection.kind: reference.
    • Data & Output: Managing streaming responses, structured outputs (using outputs, StructuredResult, and cast), and tracing operations.

    For specific data shapes, frontmatter fields, and model types, refer to the Schema Reference.

  6. Understand the Prompty Data Model

    main

    The Prompty schema defines the structure for .prompty files, runtime configurations, tool definitions, and message shapes. The schema is the source of truth for how prompts are structured and how the runtime interacts with LLM providers.

    Key components include:

    • Prompt File Core: Defines the Model and Template structures.
    • Models and Connections: Configures how to connect to LLM providers (e.g., via ApiKeyConnection, OAuthConnection, or FoundryConnection).
    • Tools: Defines how the agent can interact with external functions (e.g., FunctionTool, McpTool, OpenApiTool).
    • Messages: Defines the structure of conversation history using Message and ContentPart objects.
    • Agentic Runtime Controls: Manages execution flow via TurnOptions (e.g., maxIterations, contextBudget).
  7. Choose a Prompty runtime implementation

    main

    Prompty supports multiple language runtimes that all share the same .prompty file format. You can choose a runtime based on your existing stack. While the .prompty files are portable, the installation methods, API styles, and provider package names vary by language.

    LanguageStatusPackage
    Python✅ Stable (alpha)prompty on PyPI
    TypeScript✅ Stable (alpha)@prompty/core on npm
    C#✅ AlphaPrompty.Core, Prompty.OpenAI, Prompty.Foundry, Prompty.Anthropic on NuGet
    Rust✅ Alphaprompty, prompty-openai, prompty-foundry, prompty-anthropic on crates.io
  8. Manage LLM provider connections in Prompty VS Code extension

    main

    Connections in the Prompty VS Code extension define how the extension communicates with LLM providers (OpenAI, Anthropic, or Microsoft Foundry). They store endpoints, authentication credentials, and provider-specific settings, allowing you to run .prompty files without manually managing environment variables.

    Supported Providers

    ProviderAuth MethodModel Discovery
    OpenAIAPI key✅ Lists available models via the OpenAI API
    AnthropicAPI key✅ Lists available models via the Anthropic API
    Microsoft FoundryMicrosoft Entra ID / API key✅ Lists deployed models from your Foundry project

    Connection Resolution Order

    When running a .prompty file, the extension selects a connection using this priority:

    1. Frontmatter model.connection: Explicitly specified connection name in the .prompty file.
    2. Provider default: The connection marked as isDefault for the provider specified in model.provider.
    3. Any default: Falls back to any connection marked as default if no provider-specific default is found.
  9. Overview of Tools in Prompty

    main

    Tools extend LLM capabilities beyond text generation. They are defined in the .prompty file's frontmatter under the tools: key. When a prompt executes, the runtime passes these definitions to the LLM. If the model requests a tool, the agent loop handles the execution and feeds the result back into the conversation.

    Every tool requires a name, a kind (which determines its type), and an optional description.

    tools:
      - name: get_weather
        kind: function
        description: Get current weather for a city
        parameters:
          - name: city
            kind: string
            required: true
  10. What is Prompty?

    main

    Prompty is a markdown file format for LLM prompts. A .prompty file combines structured YAML frontmatter (containing model configuration, inputs, tools, and template config) with a markdown body (containing role markers, instructions, and template variables).

    The runtime processes these files through a pipeline: loading the file into a typed object, rendering template variables, parsing the markdown into chat messages (system/user/assistant), and executing the request via a provider and model configuration.

  11. What is a Prompty file?

    main

    A .prompty file is a markdown-based file format used to define LLM prompts. It consists of two main parts:

    1. Frontmatter: A structured metadata section (YAML) that defines model configuration, input/output schemas, tools, and template settings.
    2. Markdown Body: The actual instructions for the LLM.

    When parsed, a .prompty file produces a Prompty instance. Runtime loaders can resolve references within the frontmatter such as ${env:VAR} for environment variables and ${file:relative/path} for file references. Note that file references are typically scoped to the .prompty file's directory tree by default.

  12. What is a .prompty file?

    main

    A .prompty file is a Markdown file containing YAML frontmatter that defines the LLM prompt configuration, including the model, provider, and connection details.

    Example .prompty structure:

    ---
    name: greeting
    model:
      id: gpt-4o-mini
      provider: openai
      connection:
        kind: key
        endpoint: ${env:OPENAI_BASE_URL}
        apiKey: ${env:OPENAI_API_KEY}
    ---
    system:
    You are a helpful assistant.
    
    user:
    Hello, my name is {{name}}. {{question}}