Grammar-Constrained LLM Attribute Generation for Hallucination Reduction

Resolve Bottlenecks,
Find Innovative Solutions
Generate Solutions

Solution Overview

Problem

Generative language models, such as LLMs, tend to hallucinate, providing incorrect or irrelevant outputs due to incomplete training or fine-tuning, and existing solutions like prompt engineering and classifiers face limitations in correcting errors and scaling.

Innovation Solution

Classify the input to determine its category, obtain a grammar defining valid sequences of symbols for that category, and use a generative language model to generate a sequence of symbols that conform to the grammar, applying a mask to reduce probabilities of non-compliant tokens.

Engineering Contradictions & Design Principles

VSEngineering Contradiction Analysis

1Reliability

If prompt engineering is used to increase specificity of textual input, then hallucination is reduced, but the LLM may still not adhere to instructions when the textual description is particularly large

Engineering Contradiction:
Improveaccuracy of outputVSAvoidcomplexity of constraint enforcement
Core Design Contradiction:
ReliabilityVSDevice complexity

Solution Approach 1:

The patent introduces a grammar-based constraint system as an intermediary between the LLM and the generation process. The grammar defines valid sequences of symbols and acts as a mediator that guides the LLM to produce outputs conforming to desired terminology and structure, without requiring direct instruction following in the prompt

Inventive Principle:
Principle #24Intermediary (Mediator)

Solution Approach 2:

The patent modifies the probability parameters of token selection by applying masks that reduce or eliminate probabilities of tokens not compliant with the grammar. This changes the parameter space of valid outputs, constraining the LLM to generate only grammatically correct sequences

Inventive Principle:
Principle #35Parameter changes

2Manufacturing precision

If post-generation modification of textual description is attempted, then terminology can be corrected, but tokens occurring after modified tokens could have been different had the modified tokens appeared in the original sequence

Engineering Contradiction:
Improveterminology accuracyVSAvoidloss of alternative token information
Core Design Contradiction:
Manufacturing precisionVSLoss of information

Solution Approach 1:

The patent applies grammar constraints during the generation process itself, before the sequence is complete. By constraining token selection at each step according to the grammar, the system ensures consistency throughout the entire sequence without requiring post-generation modification

Inventive Principle:
Principle #10Preliminary action

Solution Approach 2:

The patent implements a feedback mechanism where the grammar rules continuously guide token selection during generation. The system checks each generated token against the grammar and adjusts subsequent token probabilities accordingly, maintaining consistency throughout the sequence

Inventive Principle:
Principle #23Feedback

3Reliability

If a classifier is used to describe attributes, then scaling challenges arise when new attributes need to be added

Engineering Contradiction:
Improveclassification accuracyVSAvoidability to add new attributes
Core Design Contradiction:
ReliabilityVSAdaptability or versatility

Solution Approach 1:

The patent creates a universal grammar-based framework that can handle multiple attributes and categories through a single system. The grammar can be configured to define valid sequences for different categories (e.g., shoes, shirts) and their attributes, allowing the same LLM to handle diverse classification tasks without requiring separate classifiers for each attribute

Inventive Principle:
Principle #6Universality (Multi-functionality)

Data Source

PatentUS20250292022A1Describing attributes of an input using a grammar-constrained generative language model
Publication Date: 2025.09.18 SHOPIFY INC
  • US20250292022A1 patent drawing
  • US20250292022A1 patent drawing
  • US20250292022A1 patent drawing

AI summary

One drawback of generative language models, e.g. large language models (LLMs), is their tendency to “hallucinate”. To address at least this technical problem of hallucination, in some examples, an input may be classified to determine a category associated with the input. In some examples, the input may be an image. A grammar may be obtained based on the determined category. The grammar may define valid sequences of symbols describing attributes of the category. A generative language model may be used to generate a sequence of symbols describing one or more attributes associated with the input. The sequence may be based on the input and conform to the grammar. In some examples, the generative language model may be an LLM.