# TypeChat — Schema-First Natural Language UIs > Build typed natural language interfaces by turning intent into validated JSON via TypeScript types. Replace prompt engineering with schema engineering. ## Install Save as a script file and run: # TypeChat — Schema-First Natural Language UIs > Build typed natural language interfaces by turning intent into validated JSON via TypeScript types. Replace prompt engineering with schema engineering. ## Quick Use 1. Install: ```bash npm install typechat ``` 2. Run: ```bash node -e "import('typechat').then(()=>console.log('typechat ok')).catch(e=>{console.error(e); process.exit(1);})" ``` 3. Verify: - Run one example project and confirm invalid model output is repaired into valid typed JSON. --- ## Intro Build typed natural language interfaces by turning intent into validated JSON via TypeScript types. Replace prompt engineering with schema engineering. - **Best for:** Product teams who need typed actions (APIs, workflows) from an LLM with validation and repair loops - **Works with:** TypeScript/JavaScript, any LLM backend, JSON schema-style validation flows - **Setup time:** 12 minutes ### Quantitative Notes - Setup time ~12 minutes (npm install + run one example in the repo) - GitHub stars + forks (verified): see Source & Thanks - Typical loop: generate JSON → validate → repair (1–2 retries) --- ## Practical Notes If you’re building an agent that triggers actions, define a narrow union type for allowed intents and keep each intent payload minimal. Add deterministic validation (schema + business rules) and log all repairs—repairs are where many hidden bugs appear. Over time, grow the schema set rather than growing prompts. **Safety note:** Always validate typed JSON with business rules (not just schema) before executing real actions. ### FAQ **Q: Do I still need prompt engineering?** A: Much less. You focus on defining types/schemas; prompts become smaller and more stable. **Q: How does it handle invalid JSON?** A: It validates and can re-prompt the model to repair non-conforming output. **Q: Is it only for TypeScript apps?** A: TypeChat provides TypeScript/JS support, and the repo also references other language variants. --- ## Source & Thanks > GitHub: https://github.com/microsoft/TypeChat > Owner avatar: https://avatars.githubusercontent.com/u/6154722?v=4 > License (SPDX): MIT > GitHub stars (verified via `api.github.com/repos/microsoft/TypeChat`): 8,652 > GitHub forks (verified via `api.github.com/repos/microsoft/TypeChat`): 413 --- # TypeChat——用类型定义自然语言界面 > 通过 TypeScript 类型把用户意图约束为可校验的 JSON 输出,构建更安全、可维护的自然语言界面;用 schema engineering 替代脆弱的 prompt engineering。 ## 快速使用 1. 安装: ```bash npm install typechat ``` 2. 运行: ```bash node -e "import('typechat').then(()=>console.log('typechat ok')).catch(e=>{console.error(e); process.exit(1);})" ``` 3. 验证: - Run one example project and confirm invalid model output is repaired into valid typed JSON. --- ## 简介 通过 TypeScript 类型把用户意图约束为可校验的 JSON 输出,构建更安全、可维护的自然语言界面;用 schema engineering 替代脆弱的 prompt engineering。 - **适合谁(Best for):** 需要把 LLM 输出变成“可执行的类型化动作”(API/工作流)并做校验与修复的产品团队 - **兼容工具(Works with):** TypeScript/JavaScript、任意 LLM 后端、JSON schema 风格的校验与修复流程 - **安装时间(Setup time):** 12 分钟 ### 量化信息 - 跑通约 12 分钟(npm 安装 + 跑一个示例) - GitHub stars + forks(已核验):见「来源与感谢」 - 典型流程:生成 JSON → 校验 → 修复(1–2 次重试) --- ## 实战要点 做“会触发动作”的 agent 时,建议先把允许的意图收敛成一个窄的 union type,并让每个 intent 的 payload 尽量小。加入确定性的校验(schema + 业务规则)并记录所有修复过程——修复环节往往暴露隐藏 bug。长期演进优先扩展 schema 集,而不是无止境堆 prompt。 **安全提示:** 在执行真实动作前,务必用业务规则做二次校验(不仅仅是 schema 校验)。 ### FAQ **Q: 还需要做 prompt 工程吗?** A: 需求会小很多:重点转向类型/Schema 设计,prompt 更短也更稳。 **Q: 模型输出不是合法 JSON 怎么办?** A: 先校验,再通过进一步交互让模型修复为符合类型的输出。 **Q: 只能用于 TypeScript 吗?** A: 核心支持 TypeScript/JS;仓库也提供其它语言的实现/说明链接。 --- ## 来源与感谢 > GitHub:https://github.com/microsoft/TypeChat > Owner avatar:https://avatars.githubusercontent.com/u/6154722?v=4 > 许可证(SPDX):MIT > GitHub stars(已通过 `api.github.com/repos/microsoft/TypeChat` 核验):8,652 > GitHub forks(已通过 `api.github.com/repos/microsoft/TypeChat` 核验):413 --- Source: https://tokrepo.com/en/workflows/typechat-schema-first-natural-language-uis Author: Agent Toolkit