Auto-Generating JSON-LD: Page Signals, Type Heuristics, and a Careful Gemini Prompt

Jun 04, 2026 - 17:23
Updated: 28 days ago
0 3
Auto-Generating JSON-LD: Page Signals, Type Heuristics, and a Careful Gemini Prompt

This article explores a robust pipeline for auto-generating JSON-LD by separating fact extraction from language model generation. By using deterministic heuristics to classify page types and extracting signals directly from the DOM, the system prevents hallucinations. The LLM is then constrained to fill only known fields, leaving placeholders for missing data to ensure accuracy and reliability in structured data output.

Why Does Hallucination Matter in Structured Data?

The naive approach to generating structured data for web pages often involves a single, open-ended prompt. A developer might provide a URL to a large language model and ask it to write the corresponding JSON-LD. This method appears efficient but carries significant risks. When an LLM is handed a bare URL, it tends to produce schema that looks syntactically perfect but is factually incorrect. The model may guess an author when none exists, invent a publication date, or assign a price to a commerce page that appears nowhere in the markup.

This type of error is particularly dangerous because the output validates and parses correctly. It ships to production without triggering immediate errors. However, search engines and AI engines may read these fabricated details as confirmed facts. For a tool intended for direct production use, this invisible failure mode is unacceptable. A lie that looks like truth is far more damaging than an empty field, as it misleads downstream systems that rely on the data for indexing and retrieval.

How Does Deterministic Signal Extraction Work?

To mitigate these risks, the pipeline must be built backwards from the point of failure. The language model should never see a raw URL, nor should it be allowed to decide what the facts are. Instead, the page must be read, the facts extracted, and the page type determined by deterministic code before the model is invoked. The model's role is narrowed to a single task: taking known facts and a known shape to emit well-formed JSON-LD. This ensures that everything prone to hallucination is settled before the model writes a single word.

The first step involves fetching the page and pulling structured signals directly from the Document Object Model. This stage uses no model, relying solely on parsing. A fixed set of signals is extracted, including the title, meta description, and canonical URL, which represent the page's own identity claims. Headings are captured up to a limit of thirty to prevent pathological pages from overwhelming the payload. Images are limited to ten, capturing only the source and alt text, as alt text is the primary image content a schema block can carry.

Additional signals include the author, searched across multiple selector families such as rel attributes, specific classes, and itemprop tags. Publication dates are read from time elements and meta tags. Breadcrumbs are extracted from navigation elements, and price markers are identified to signal commerce pages. FAQ markers are also detected. The result is a plain signal bundle that contains facts, not interpretations. If an author is not found, the field is null. This null value is critical, as it protects downstream steps from inventing a name.

What Is the Role of Heuristics in Type Classification?

With the signal bundle in hand, the system decides the page type using plain code before any model call. This process runs as an ordered ladder, stopping at the first match. The order is crucial because conditions often overlap. For example, a product page might also have an author and a date. By checking for price markers first, the system resolves the type to product rather than misclassifying it as a blog post. The ladder reads top to bottom, and the first hit wins.

This pre-model classification serves three primary purposes. First, it provides deterministic grounding. When the model is told the page type, it writes schema for a known shape. It does not guess the shape and the content simultaneously. Splitting the classification decision from the content generation removes the highest-variance decision from the part of the system that can hallucinate. Second, it reduces costs. A rule that reads a boolean is free, whereas spending an LLM call to classify a page that can be classified with a string match is wasteful at scale.

Third, it creates a constrained LLM job. The smaller the question handed to the model, the more reliable the answer. Asking the model to produce a specific block from known steps is a tight prompt. Asking it to figure out what the page is and write schema for it is an open-ended task where models are prone to drift. By limiting the scope, the system ensures higher accuracy and consistency in the generated output.

How Does the Language Model Contribute to Accuracy?

Once the type is determined, the model runs. It receives the signal bundle and the detected type, returning typed JSON-LD. The model is instructed to return one block per applicable type, including a confidence score and a short explanation. Running the model in JSON mode ensures the response is constrained to valid JSON. This prevents the parser from having to scrape code fences out of prose or recover from stray sentences. Structured output goes in, and structured output comes back.

The most critical rule enforced in the prompt concerns missing facts. The model is instructed that any field not provided with a value must be emitted as an explicit, clearly labeled placeholder. It is forbidden from substituting a plausible value of its own. If the signal bundle indicates a null author, the author field in the output becomes a placeholder token. This is the core safety property of the tool: a gap stays a visible gap, marked for human review, rather than becoming a confident fabrication.

This approach prioritizes transparency over completeness. It is better to hand a user a block with three placeholders to complete than one with three invented values to discover later. The deterministic half of the pipeline carries the result even if the probabilistic half fails. If the model call times out or returns an error, the tool still returns the type detection and template JSON-LD blocks with the same placeholder structure. This ensures that an empty, well-shaped suggestion is always available, beating a system error.

What Are the Practical Implications for SEO and AI?

The output of this pipeline is a ready-to-paste script tag containing structured data across various types, including Article, Product, FAQPage, and HowTo. While Google retired HowTo rich results in 2023, the markup remains valuable. It hands AI engines an ordered procedure that can be reproduced faithfully, step for step, without reconstructing the sequence from prose. This is particularly useful for Generative Engine Optimization, where AI models cite structured data as a source of truth.

The full range of supported types includes WebPage, WebSite, Organization, and LocalBusiness. By ensuring that every field is either a known fact or a visible placeholder, the system maintains high integrity. This reliability is essential for tools that are pasted directly into production environments. Developers can trust that the generated schema will not mislead search engines or AI systems with fabricated data.

The key takeaway from this architecture is the importance of ordering. The instinct with capable models is to hand them the whole problem and admire the result. However, the better discipline is to identify which decisions must never be probabilistic. Classification and fact-finding should be settled in code. The model should then be allowed to do only the bounded part that remains. This pipeline is more reliable not because the model is weaker, but because it was given less room to be wrong.

Internal Resources

For those interested in the broader context of AI infrastructure and security, you might find SpaceX Acquisition of Cursor Reshapes Enterprise AI Infrastructure relevant. Additionally, understanding the importance of secure development environments is crucial, as discussed in Developer Endpoint Protection: Securing the Modern Workstation.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Christopher Holloway

Christopher Holloway is the founder and director of Progressive Robot, a UK-based technology company. A full-stack engineer with more than two decades of experience, he works across PHP development, ecommerce, Linux infrastructure, technical SEO and AI automation, and writes here on technology, AI, hardware and software.

Comments (0)

User