explaingit

microsoft/typechat

8,654TypeScriptAudience · developerComplexity · 2/5Setup · moderate

TLDR

A Microsoft open-source library that lets you add plain-English input to any app by defining TypeScript types for what the app supports, the AI model is forced to reply in that exact shape, giving you structured data instead of unpredictable free-form text.

Mindmap

mindmap
  root((TypeChat))
    What it does
      Structured NL input
      Schema validation loop
      No prompt engineering
    How it works
      TypeScript types
      Model constraints
      Auto self-correction
    Languages
      TypeScript and JS
      Python
      C#
    Getting started
      npm install
      Example projects
      GitHub Codespace
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a natural-language shopping cart where user input like 'add two apples' is automatically converted to a structured cart update object your app can process.

USE CASE 2

Add a plain-English command interface to any existing app by defining TypeScript interfaces for each supported action, no prompt engineering required.

USE CASE 3

Replace fragile LLM output parsing in your app with a validation loop that automatically asks the model to self-correct if its reply doesn't match your schema.

Tech stack

TypeScriptJavaScriptPythonC#

Getting it running

Difficulty · moderate Time to first run · 30min

Requires an API key from an LLM provider such as OpenAI or Azure OpenAI.

In plain English

TypeChat is a Microsoft open-source library for TypeScript and JavaScript (with Python and C# versions available) that helps developers build apps where users can type plain English and the app understands what they want. Think of it as a structured bridge between a conversational AI model and your application logic. Traditionally, building this kind of natural language interface meant writing complex decision trees to figure out what the user intended and what data to collect. Large language models made that easier, but introduced new problems: their replies can be unpredictable, unsafe, or in a format your app cannot process. TypeChat solves this by replacing prompt engineering with what the authors call schema engineering. The idea is straightforward. A developer writes TypeScript types that describe all the valid actions or intents the app supports. TypeChat takes those types, sends them along with the user's message to the language model, and tells the model to reply in a format that matches the types. It then checks whether the model's reply actually conforms to the schema. If it does not, TypeChat automatically sends a follow-up to the model asking it to correct the output. This validation loop means your app always receives structured, trustworthy data rather than free-form text. A simple example might be a sentiment classifier described as a TypeScript interface. A more complex one could be a shopping cart with items, quantities, and modifications. Developers add new capabilities by adding new types, which is a much more predictable process than tuning a long prose prompt. To get started, install the package from npm with a single command. The repository includes example projects you can run locally or in a browser-based GitHub Codespace, and the official documentation site covers the full API.

Copy-paste prompts

Prompt 1
I want to use TypeChat to build a natural-language todo app in TypeScript. Show me how to define the schema and handle input like 'add a task for tomorrow'.
Prompt 2
I'm setting up TypeChat with OpenAI. How do I configure the model connection and run one of the built-in example projects locally?
Prompt 3
I want to add a plain-English command interface to my existing TypeScript app using TypeChat. Show me how to define the action schema and handle the validated response.
Open on GitHub → Explain another repo

← microsoft on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.