Primitive of the day · 2026-10-05
mlx-vlm-generate-returns-dataclass
mlx_vlm.generate() returns a GenerationResult dataclass, not a str — read .text for the answer (with free stats in .generation_tps/.peak_memory/.cached_tokens); str(result) yields the full dataclass repr.
When this applies
Consuming generate() output programmatically — writing answers to files, feeding downstream prompts, parsing.
Preconditions
- Using the mlx-vlm Python API (behavior verified on v0.6.4)
Do this
Use result.text (strip as needed); never str()/f-string the result object directly into downstream text.
What you should see
Clean answer strings.
How it fails if ignored
Dataclass repr ('GenerationResult(text=...)') contaminates files, prompts, or JSON built from the output.
Do not use when
CLI usage (python -m mlx_vlm.generate), which already prints plain text.
Kind: gotcha-fix. Part of the skill MLX VLM local vision inference. Free to reuse in your own agent skills.
Get the whole skill
All 5 primitives of this skill as one package, with the order to apply them.
Buy only the primitives you need
Each primitive is 1 credit (≈ €0.10). Pick them from the list above — the button is next to each one.
Upgrade your own skill
Paste your skill; we pick the 5 primitives from the shelf that fit it best, as one bundle for 5 credits (≈ €0.50).
Upgrade my skill