Model or dataset
microsoft/TypeChat avatar
microsoft/TypeChat

TypeChat: Turning TypeScript Types into a Contract for LLM Output

TypeChat is a library that makes it easy to build natural language interfaces using types.

8,685 stars414 forksTypeScriptMIT

At a glance

What is it?
TypeChat is a Microsoft library that uses TypeScript types as the schema for validating and repairing large language model responses. It targets developers who want structured, safe LLM output without writing long prompts.
Who is it for?
Adopt TypeChat if you are a TypeScript developer building a natural language interface that needs structured intents and you want to avoid prompt engineering. Do not adopt it if your schema is highly dynamic or you cannot tolerate extra LLM calls for validation and repair.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 6 days ago.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

The Problem TypeChat Solves

Building a natural language interface usually meant writing decision trees to map user input to intent, then collecting the inputs needed for an action. Large language models removed the need for those trees, but introduced a new problem: how to force the model to reply in a shape your code can process. The README argues that prompt engineering is fragile and has a steep learning curve as prompts grow. TypeChat replaces prompt engineering with schema engineering. Instead of writing instructions, you define TypeScript types that represent the intents your application supports. The library then constructs a prompt from those types, validates the model's response against them, and repairs invalid output. This is aimed at developers who already know TypeScript and want a typed contract for LLM output, not at researchers experimenting with prompt techniques.

How Schema Engineering Works

The mechanism is visible in the README's three steps. First, TypeChat builds a prompt to the LLM using your types. That means the type definitions themselves become the specification the model is asked to follow. Second, the library validates the LLM response against the schema. If validation fails, it repairs the non-conforming output through further language model interaction. This is a key design choice: rather than rejecting bad output, TypeChat sends it back to the model with feedback. Third, it summarizes the instance and confirms it aligns with user intent, and this step does not use an LLM. The summary is done with code, which keeps cost down. The README gives examples of simple sentiment interfaces and more complex shopping cart or music schemas. To add an intent, you add a type to a discriminated union. To make schemas hierarchical, you use a meta-schema that picks one or more sub-schemas based on input.

Getting Started and Running It

Installation is a single command: npm install typechat. The package targets TypeScript and JavaScript. The README links to example projects in the typescript/examples directory, and suggests trying them locally or in a GitHub Codespace. There is also documentation at microsoft.github.io/TypeChat. The repository contains separate language implementations: TypeScript is in the typescript folder, Python is in python, and C#/.NET is a separate repository at microsoft/TypeChat.net. The README shows a commented-out section for PyPI and NuGet, which implies those package managers were not yet published at the time of writing. For a TypeScript developer, the path is straightforward: define your types, import the library, and pass a user message. The exact API calls are not in the README, so you would need to consult the examples or the docs to see how to wire a model client.

Where TypeChat Falls Short

The most obvious limitation is that validation and repair rely on further LLM interaction. That adds latency and cost for every request that initially fails validation. In a high-volume application, this could be prohibitive. The README does not mention any caching or fallback strategy for repair. Another limitation is that the schema is defined in TypeScript types, which are erased at runtime. The library must convert those types to a JSON schema or a prompt representation, and that conversion only works for types that are JSON-serializable. If your intent requires complex logic, like conditional constraints based on user history, a type definition cannot express it. TypeChat is also wrong for applications where the set of intents is not known in advance. A discriminated union requires you to enumerate all possible intents at compile time. For open-ended tasks like free-form summarization, a schema is the wrong tool.

Alternatives: Prompt Engineering vs. TypeChat

The direct alternative is prompt engineering, where you write detailed instructions in the prompt to constrain the model's output. That approach has no schema validation; you rely on the model to follow the prompt, and you parse the output yourself. TypeChat's difference is that the schema is a type, not prose. That means the validation is programmatic and the repair loop is automated. Another alternative is using a structured output feature from an LLM provider, such as OpenAI's JSON mode, but that only guarantees valid JSON, not that the JSON matches your specific shape. TypeChat goes further by mapping the response to your TypeScript types and repairing mismatches. The README positions TypeChat as a replacement for prompt engineering, not for full NLU platforms. If you need dialogue management or entity extraction beyond intents, TypeChat is not that.

Maintenance and License Considerations

The repository is under the MIT license, which is permissive. The README includes Microsoft trademark clauses, so if you modify the project, you must avoid confusion with Microsoft sponsorship. The project is not archived and had a push in August 2026, but no releases were retrieved. That absence of release tags is worth noting: you may be installing from a rolling main branch, which means breaking changes could land without a version bump. The README points to separate implementations for Python and C#, so maintenance is split across repos. For TypeScript, the package is on npm, but the README does not specify a minimum TypeScript version. You should verify that your toolchain supports the language features used in the type definitions, especially advanced types like discriminated unions and template literal types. The documentation site is the place to check for upgrade notes.

Editorial conclusion

Adopt TypeChat if you are a TypeScript developer building a natural language interface that needs structured intents and you want to avoid prompt engineering. Do not adopt it if your schema is highly dynamic or you cannot tolerate extra LLM calls for validation and repair. Before adopting, verify your TypeScript version matches the library's requirements, test with your target LLM, and check that your schema types are JSON-serializable. TypeChat is a pragmatic middle ground, but it is not a full NLU framework and its value depends on your willingness to treat types as the single source of truth.

Official sources

  1. Issues
  2. License: MIT
  3. microsoft/TypeChat on GitHub
  4. Project website
  5. README
Community notes

Community notes