A Go struct the model can't break
Give goinfer a Go struct and the model can only write JSON that fits it, so json.Unmarshal parses it. It fixes the shape, not whether the values are right.
Limit It doesn't check what the values say.
Read →A Go library · pure Go · no cgo
Import it and call it, then cross-compile it like anything else: no cgo, no daemon, no C toolchain. Constrain the output to a Go struct, and a token that would break the struct is never sampled.
go get github.com/townsendmerino/goinfer/decoder@latest github.com/townsendmerino/goinfer/tokenizer@latesttype Person struct {
Name string `json:"name"`
Age int `json:"age"`
Langs []string `json:"langs"`
Email string `json:"email,omitempty"` // omitempty (or a pointer) makes a field optional
}
g, err := constrain.GrammarFromStruct(Person{}) // struct -> JSON Schema -> grammar
mask := constrain.NewMasker(g, constrain.TokenBytes(m.Config().VocabSize, tok.TokenText), stop).StopWhenComplete()
ch, gen := m.Generate(context.Background(), ids, 128, decoder.SamplingParams{LogitProcessor: mask.Process, StopIDs: stop})
var p Person
check(json.Unmarshal([]byte(raw), &p), "unmarshal") // the shape is guaranteed; a value can still be wrong
Pick the computer closest to yours. goinfer says what fits, how fast it measured on that hardware, and how that compared with Ollama in the same session.
goinfer-chat pull qwen2.5-coder-0.5bgoinfer-chat pull Qwen/Qwen2.5-Coder-1.5B-Instruct-GGUF:q4_k_mgoinfer-chat pull qwen3.5-0.8bgoinfer-chat pull phi3-mini-4kgoinfer-chat pull qwen3-vl-2bgoinfer-chat pull granite-4.0-h-tinygoinfer-chat pull gpt-oss-20bgoinfer-chat pull gemma-4-26b-a4bA Go library. Ask a question, get a filled-in struct back. The Use it from Go page walks through the smallest program, struct and schema constraints, and per-field confidence.
go get github.com/townsendmerino/goinfer/decoder@latest github.com/townsendmerino/goinfer/tokenizer@latest
One file with a model inside. Download, run, ask. Nothing to install.
./goinfer-chat-0.5b-<os>-<arch>
OpenAI- and Anthropic-compatible. Setup notes for Claude Code, opencode and jevx.
goinfer-serve -web -model ~/models/model.gguf
Ask how a model would be placed on your machine, and whether it fits, without starting a chat.
goinfer-chat fit <model>
If you read one chapter of the book
How measurements in this repo have gone wrong, why profiling Go is not enough here, and what the codebase does instead. Written for someone who knows Go and not machine learning.
Each of these has a writeup: the problem, what goinfer does, what was measured, and what it doesn't do.
Give goinfer a Go struct and the model can only write JSON that fits it, so json.Unmarshal parses it. It fixes the shape, not whether the values are right.
Limit It doesn't check what the values say.
Read →When a model starts a tool call, goinfer holds it to valid JSON, a tool you supplied, and that tool's argument schema. It does not pick the tool for the model.
Limit It doesn't choose the right tool.
Read →Cancel one generation by id, or halt them all from an HTTP call, a file or a signal. Control sits on its own Unix socket, away from the API.
Limit It doesn't sandbox what a client does with text it already has.
Read →Each enum, boolean and integer field of a constrained JSON answer comes back with the model's own probability over the answers the schema allowed.
Limit It isn't the probability that the answer is right.
Read →goinfer answers a choice among a few options from one read of the prompt, with no generation. It ships; its accuracy on a real model is not yet measured.
Limit It hasn't been graded on a real model.
Read →Each model family is compared with HuggingFace's own implementation, the result is printed on the Models page, and the label says how strong the check was.
Limit It doesn't cover every quantization on every machine.
Read →The book
11 chapters on how a language model actually runs, for someone who knows Go and not machine learning. Read it here.