---
title: "The hallucinating classifier pattern"
url: https://daily.dev/posts/the-hallucinating-classifier-pattern-kly8mghua
source_url: http://softwaredoug.com/blog/2026/08/10/hypothetical-classifications.html
type: article
source: "Software Doug"
published: 2026-08-10T20:38:44.029Z
updated: 2026-08-10T20:39:09.625Z
tags: ["machine-learning", "llm", "vector-search", "embeddings", "pydantic"]
reading_time: 4
upvotes: 2
comments: 1
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# The hallucinating classifier pattern

**[Software Doug](https://daily.dev/sources/softwaredoug)** · 4 min read · 2 upvotes · 1 comments

## Summary

A practical pattern for LLM-based classification at scale: instead of constraining the LLM to a large enum of legal vocabulary values (which hits API limits and is expensive), let the LLM freely hallucinate plausible-but-fake category labels for a given input. Then use embedding similarity (e.g., MiniLM dot product) to map the hallucinated label to the closest real entry in your taxonomy. This avoids shipping large schemas to the model, works with cheaper/smaller LLMs, and sidesteps OpenAI's structured output enum limits.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <http://softwaredoug.com/blog/2026/08/10/hypothetical-classifications.html>

## Questions this post answers

### How do I classify text into a large taxonomy with an LLM without hitting structured output enum limits?

Instead of constraining the LLM to a list of legal values, prompt it to freely generate a plausible-but-fake label for the input. Then embed that hallucinated label and dot-product it against pre-computed embeddings of your real taxonomy entries to find the closest match. This avoids shipping large schemas to the model, works with cheaper models, and sidesteps OpenAI's structured output enum size limits.

_Developers solving LLM classification at scale share patterns like this on daily.dev._

### What is the upper limit on enums in OpenAI structured outputs?

OpenAI imposes an upper limit on the number of enum values you can send in a structured output schema. When a taxonomy has hundreds of categories, this constraint makes the standard Pydantic Literal approach impractical, which is one motivation for the hallucination-then-embedding-retrieval pattern as an alternative.

_Teams hitting OpenAI API constraints on taxonomy classification discuss workarounds on daily.dev._

## Community discussion

Top comments from developers on daily.dev.

**@agustinbarrientos** · 0 upvotes

> I'd send the item for review when the top two embedding scores nearly tie.

## Similar posts on daily.dev

- [Teaching a Vision Model to See Like a Human Annotator—and Catching It When It Lies](https://daily.dev/posts/teaching-a-vision-model-to-see-like-a-human-annotator-and-catching-it-when-it-lies-unren10pj) · DevBlogs · 1 upvotes · 0 comments
- [5 Practical Techniques to Detect and Mitigate LLM Hallucinations Beyond Prompt Engineering](https://daily.dev/posts/5-practical-techniques-to-detect-and-mitigate-llm-hallucinations-beyond-prompt-engineering-c2nv4kkuh) · Machine Learning Mastery · 1 upvotes · 0 comments
- [Hallucinations in LLMs Are Not a Bug in the Data](https://daily.dev/posts/hallucinations-in-llms-are-not-a-bug-in-the-data-jy5db8x1i) · Towards Data Science · 1 upvotes · 0 comments
- [OpenAI Study Investigates the Causes of LLM Hallucinations and Potential Solutions](https://daily.dev/posts/openai-study-investigates-the-causes-of-llm-hallucinations-and-potential-solutions-l15kdmz0z) · InfoQ · 4 upvotes · 0 comments
- [To trust an LLM, make lying harder than telling the truth](https://daily.dev/posts/to-trust-an-llm-make-lying-harder-than-telling-the-truth-55ld1vchp) · Swimm · 1 upvotes · 1 comments

---

Tags: [#machine-learning](https://daily.dev/tags/machine-learning), [#llm](https://daily.dev/tags/llm), [#vector-search](https://daily.dev/tags/vector-search), [#embeddings](https://daily.dev/tags/embeddings), [#pydantic](https://daily.dev/tags/pydantic)

[View this post on daily.dev](https://daily.dev/posts/the-hallucinating-classifier-pattern-kly8mghua)
