{"id":14980561,"url":"https://github.com/thekevinscott/autogrammer","last_synced_at":"2026-02-17T06:05:05.319Z","repository":{"id":332791824,"uuid":"731095617","full_name":"thekevinscott/Autogrammer","owner":"thekevinscott","description":"End-to-end structured output for browser LLMs. Constrain Transformers.js/web-llm to valid JSON/SQL via GBNF grammars.","archived":false,"fork":false,"pushed_at":"2026-01-15T15:21:02.000Z","size":2487,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-29T22:34:19.242Z","etag":null,"topics":["gbnf","llm","structured-output","transformersjs","web-llm"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/thekevinscott.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-12-13T10:50:58.000Z","updated_at":"2026-01-15T15:21:08.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/thekevinscott/Autogrammer","commit_stats":null,"previous_names":["thekevinscott/autogrammer"],"tags_count":92,"template":false,"template_full_name":null,"purl":"pkg:github/thekevinscott/Autogrammer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekevinscott%2FAutogrammer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekevinscott%2FAutogrammer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekevinscott%2FAutogrammer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekevinscott%2FAutogrammer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thekevinscott","download_url":"https://codeload.github.com/thekevinscott/Autogrammer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thekevinscott%2FAutogrammer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29535934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-17T05:00:25.817Z","status":"ssl_error","status_checked_at":"2026-02-17T04:57:16.126Z","response_time":100,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gbnf","llm","structured-output","transformersjs","web-llm"],"created_at":"2024-09-24T14:02:01.057Z","updated_at":"2026-02-17T06:05:05.308Z","avatar_url":"https://github.com/thekevinscott.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ccenter\u003e\n\u003ch1\u003eAutogrammer\u003c/h1\u003e\n\n\u003ca href=\"https://www.npmjs.com/package/autogrammer\"\u003e\u003cimg alt=\"Latest Autogrammer NPM Version\" src=\"https://badge.fury.io/js/autogrammer.svg\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/thekevinscott/autogrammer/blob/master/LICENSE\"\u003e\u003cimg alt=\"License for Autogrammer\" src=\"https://img.shields.io/npm/l/autogrammer\" /\u003e\u003c/a\u003e\n\u003ca href=\"https://www.npmjs.com/package/autogrammer\"\u003e\u003cimg alt=\"Downloads per week on NPM for Autogrammer\" src=\"https://img.shields.io/npm/dw/autogrammer\" /\u003e\u003c/a\u003e\n\u003c/center\u003e\n\nAutogrammer constrains the output of language models (LLMs) to generate syntactically valid JSON or SQL. \n\nBy leveraging grammars, Autogrammer ensures that an LLM generates output adhering to specific structures and syntax, even with smaller models. \n\n_Autogrammer is still being actively developed and should be considered in alpha_\n\n## Why Autogrammer?\n\nLLMs produce a probability distribution over possible next tokens. By manipulating this distribution, you can constrain what the LLM outputs, for example by only allowing syntactically valid next tokens. For smaller LLMs (like ones that run in a browser) this is particularly valuable. It's a harness that guides them toward correct output.\n\nGBNF is a grammar format for defining syntactic validity. At inference time, Autogrammer uses the GBNF grammar to mask invalid tokens from the model's logits, guaranteeing parseable output.\n\nSimilar packages exist in the Python ecosystem: [Outlines](https://github.com/dottxt-ai/outlines) and [guidance](https://github.com/guidance-ai/guidance).\n\n## Use Cases\n\n- 💻 Live code generation in the browser\n- 🗣️ Natural language to SQL conversion\n- 🎇 Generating visualizations from text descriptions\n- 🌳 Offline apps\n- 🕵️ When you want your data staying private\n\n## Key features\n\n- **Bring your own model** \u0026mdash; Works seamlessly with `Transformers.js`, `web-llm`, and REST endpoints for `llama.cpp` and `llamafile`, allowing you to use your preferred LLM.\n\n- **Support for `JSON` and `SQL`** \u0026mdash; With syntactic validity guaranteed by GBNF grammars.\n\n- **Schema support** \u0026mdash; Provide schemas** (database schema or JSON schema) to further restrict possible output and ensure semantic correctness.\n\n- **Plugins** \u0026mdash; (*Coming soon*) Enable additional functionality, such as RAG, on-the-fly error correction, and more.\n\n## Installation\n\n```bash\nnpm install autogrammer\n```\n\n## Quickstart\n\n```javascript\nimport { pipeline } from '@xenova/transformers'\nimport { Autogrammer } from 'autogrammer'\n\n// Load your preferred model\nconst model = pipeline('text-generation', 'Xenova/gpt2')\n\n// Create Autogrammer for JSON output\nconst autogrammer = new Autogrammer({\n  language: 'json',\n})\n\n// Tell the model what to generate\nconst prompt = 'Write me JSON that captures the following address: 1600 Pennsylvania Avenue NW, Washington, DC 20500'\n\n// Run\nconst response = await autogrammer.execute(prompt)\n\n// See the generated JSON\nconsole.log(response) // { ... json object }\n```\n\n## Packages\n\nAutogrammer is made up of several packages:\n\n**Grammar packages** (in [GBNF repo](https://github.com/thekevinscott/GBNF)):\n- [`gbnf`](https://github.com/thekevinscott/GBNF) - Parses a GBNF grammar into a graph of rules, which can be used to determine the validity of a next token. Also enables the creation of GBNF grammars dynamically.\n- [`json2gbnf`](https://github.com/thekevinscott/GBNF) - Generates a GBNF grammar for JSON, with optional JSON schema\n- [`sql2gbnf`](https://github.com/thekevinscott/GBNF) - Generates a GBNF grammar for SQL, with optional database schema\n\n**Orchestration packages** (in this repo):\n- [`contort`](packages/contort/README.md) - Implements a Logits post-processor that restricts LLM output to only include valid next tokens\n- [`autogrammer`](packages/autogrammer/javascript/) - Orchestrates support for SQL and JSON grammar generation with a variety of LLM models.\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthekevinscott%2Fautogrammer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthekevinscott%2Fautogrammer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthekevinscott%2Fautogrammer/lists"}