<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/the-hallucinating-classifier-pattern-kly8mghua" -->

---
title: The hallucinating classifier pattern | daily.dev
description: 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...
canonical: https://daily.dev/posts/the-hallucinating-classifier-pattern-kly8mghua
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: The hallucinating classifier pattern | daily.dev
og:description: 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...
og:url: https://daily.dev/posts/the-hallucinating-classifier-pattern-kly8mghua
og:image: https://api.daily.dev/og/posts/KLY8MghUA.png
og:image:alt: The hallucinating classifier pattern
og:image:width: 1200
og:image:height: 630
og:locale: 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 can I classify search queries into a taxonomy with hundreds of categories without hitting the OpenAI structured outputs enum limit?

Instead of sending the full list of legal categories as an enum, prompt the LLM to invent a plausible but fake classification label for the query, then embed that fake label with a model like MiniLM and match it via dot product similarity against precomputed embeddings of the real taxonomy entries, picking the closest real match. This avoids schema size limits and lets you use cheaper, smaller models since the full vocabulary never has to be sent.

_Developers wiring up LLM classification pipelines can find implementation patterns like this through daily.dev._

### Why would I want an LLM to hallucinate a fake product category instead of forcing it to pick from a real list?

Hallucinating a fake but plausible category and then resolving it via embedding similarity to the real taxonomy avoids the need to ship the entire vocabulary schema on every request, works around upper limits on the number of enum values structured output APIs allow, and lets smaller, cheaper models handle classification since they no longer need the full legal list in context.

_Anyone weighing structured outputs against embedding-based resolution for LLM tasks tracks approaches like this 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
- [Why Do LLMs Lie?](https://daily.dev/posts/why-do-llms-lie--ntzewhtr7) · ByteByteGo · 2 upvotes · 1 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
- [LLM hallucinations in production](https://daily.dev/posts/llm-hallucinations-in-production-bs191p5s1) · portkey · 1 upvotes · 0 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)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"The hallucinating classifier pattern","url":"https://daily.dev/posts/the-hallucinating-classifier-pattern-kly8mghua","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/the-hallucinating-classifier-pattern-kly8mghua"},"datePublished":"2026-08-10T20:38:44.029Z","dateModified":"2026-09-14T08:44:27.606Z","description":"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...","image":"https://media.daily.dev/image/upload/s--qPvKM23u--/f_auto/v1722860399/public/Placeholder%2009","thumbnailUrl":"https://media.daily.dev/image/upload/s--qPvKM23u--/f_auto/v1722860399/public/Placeholder%2009","isAccessibleForFree":true,"articleSection":"Software Doug","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Software Doug","logo":"https://media.daily.dev/image/upload/s--i8zvexsI--/f_auto,q_auto/v1774514120/logos/softwaredoug?_a=BAMAMiWQ0","url":"https://daily.dev/sources/softwaredoug"},"commentCount":1,"discussionUrl":"https://daily.dev/posts/the-hallucinating-classifier-pattern-kly8mghua","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":1}],"keywords":"machine-learning,llm,vector-search,embeddings,pydantic","timeRequired":"PT4M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Software Doug","item":"https://daily.dev/sources/softwaredoug"},{"@type":"ListItem","position":3,"name":"The hallucinating classifier pattern"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/the-hallucinating-classifier-pattern-kly8mghua","comment":[{"@type":"Comment","text":"I’d send the item for review when the top two embedding scores nearly tie.","datePublished":"2026-08-11T08:17:57.604Z","url":"https://daily.dev/posts/KLY8MghUA#c-HCM8BDyEN","author":{"@type":"Person","name":"Agustin Barrientos","url":"https://daily.dev/agustinbarrientos","image":"https://media.daily.dev/image/upload/s--5ayxQnqn--/f_auto/v1788281802/avatars/avatar_wQYYVe5Tbj0NJ7C7qPoa8?_a=BAMAMicg0"}}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/the-hallucinating-classifier-pattern-kly8mghua#faq","mainEntity":[{"@type":"Question","name":"How can I classify search queries into a taxonomy with hundreds of categories without hitting the OpenAI structured outputs enum limit?","acceptedAnswer":{"@type":"Answer","text":"Instead of sending the full list of legal categories as an enum, prompt the LLM to invent a plausible but fake classification label for the query, then embed that fake label with a model like MiniLM and match it via dot product similarity against precomputed embeddings of the real taxonomy entries, picking the closest real match. This avoids schema size limits and lets you use cheaper, smaller models since the full vocabulary never has to be sent. Developers wiring up LLM classification pipelines can find implementation patterns like this through daily.dev."}},{"@type":"Question","name":"Why would I want an LLM to hallucinate a fake product category instead of forcing it to pick from a real list?","acceptedAnswer":{"@type":"Answer","text":"Hallucinating a fake but plausible category and then resolving it via embedding similarity to the real taxonomy avoids the need to ship the entire vocabulary schema on every request, works around upper limits on the number of enum values structured output APIs allow, and lets smaller, cheaper models handle classification since they no longer need the full legal list in context. Anyone weighing structured outputs against embedding-based resolution for LLM tasks tracks approaches like this on daily.dev."}}]}
```

