Sanity

How to Use Structured CMS Content for Better AI Answers

Learn how structured content AI workflows unlock smarter, more accurate LLM responses. Discover schema design, GROQ queries, and content modeling strategies for AI-ready CMS architecture.

June 26, 202610 min readMuhammad Zohaib Ramzan
How to Use Structured CMS Content for Better AI Answers

Why content structure matters for AI

When an AI model processes your content, it doesn’t read between the lines the way a human does. It relies on explicit signals — field names, semantic relationships, and consistent data shapes — to understand what a piece of content is about and how its parts relate to one another. Without structure, even the most well-written prose becomes an undifferentiated blob of tokens.

Structured content AI pipelines depend on the CMS being a reliable source of truth. When your content is modeled with clear types, predictable fields, and enforced validation, the AI can confidently extract facts, relationships, and context. A product description stored in a typed product document with discrete name, price, features, and category fields is infinitely more useful to an LLM than the same information buried in a single rich-text blob.

Structure also enables retrieval-augmented generation (RAG) — the technique where AI answers are grounded in your actual content rather than hallucinated from training data. For RAG to work well, your content chunks need to be semantically coherent, consistently sized, and richly annotated with metadata. A well-designed CMS schema is the foundation that makes this possible.

Finally, structure future-proofs your content. As AI capabilities evolve, the models consuming your content will change. But if your content is properly structured today, it can be re-queried, re-chunked, and re-embedded without a costly content migration.

How LLMs interpret structured vs unstructured content

Large language models are trained on vast amounts of unstructured text, which means they are surprisingly good at parsing prose. However, when it comes to factual accuracy, consistency, and grounding, structured content wins decisively. An LLM given a JSON object with clearly labeled fields will produce more reliable answers than one given a paragraph that happens to contain the same information.

Consider the difference between these two inputs. Unstructured: “Our Pro plan, which costs $49 per month, includes up to 10 users and was updated last March.” Structured: a typed object with fields plan: "Pro", price: 49, currency: "USD", billingCycle: "monthly", maxUsers: 10, and lastUpdated: "2024-03-01". The structured version eliminates ambiguity, is trivially parseable, and can be validated before it ever reaches the model.

Unstructured content also introduces noise. Formatting artifacts, editorial asides, and inconsistent terminology all degrade the quality of AI-generated answers. When you feed an LLM a Portable Text body that mixes product specs with marketing copy, it has to do extra work to separate signal from noise — and it doesn’t always succeed.

The practical implication is clear: the more you can move facts, relationships, and metadata out of free-form text and into typed, validated fields, the better your AI answers will be. Rich text should be reserved for narrative content where prose genuinely adds value.

Designing Sanity schemas for AI consumption

Sanity’s schema system gives you fine-grained control over the shape of your content, making it an excellent foundation for structured content AI workflows. The key principle is to model your content around the questions your AI will need to answer, not just around how it will be displayed.

Start by identifying the atomic facts in your domain. For a knowledge base, these might be: product name, version, supported platforms, known limitations, and related articles. Each of these should be a discrete, typed field — not a sentence in a description block. Use string for short text, text for longer prose, number for quantities, reference for relationships, and array of typed objects for lists of structured items.

Use validation rules aggressively. Required fields, maximum lengths, and enum constraints don’t just improve data quality for humans — they guarantee that every document the AI receives has a predictable, complete shape. An AI that can rely on author.name always being present and category always being a valid reference will produce far more consistent outputs than one working with optional, sometimes-missing fields.

Consider adding AI-specific metadata fields to your schemas. Fields like aiSummary (a concise, human-written summary optimized for embedding), keyFacts (an array of discrete factual statements), or contentVersion (to track when content was last reviewed for accuracy) can dramatically improve the quality of AI-generated answers without changing how content is displayed to end users.

GROQ queries that feed AI models

GROQ — Sanity’s Graph-Relational Object Queries language — is a powerful tool for shaping content payloads precisely for AI consumption. Rather than fetching entire documents and letting the AI figure out what’s relevant, you can use GROQ to project exactly the fields and relationships the model needs, minimizing token usage and maximizing signal density.

A well-designed AI-ready GROQ query fetches the document _id, title, excerpt, the author name via a dereference (author->name), the category title (category->title), a plain-text rendering of the body using pt::text(body), the publishedAt datetime, and the tags array. The pt::text() function is particularly valuable — it converts Portable Text to a clean string, stripping all markup so the AI receives readable prose without formatting noise.

For RAG pipelines, you’ll often want to chunk content at the section level rather than the document level. GROQ can help here too. By querying the body array and filtering for blocks with a specific style — such as h2 or h3 — you can programmatically identify section boundaries and split content into semantically coherent chunks before embedding. Each chunk should carry document-level metadata as context.

Use GROQ’s join and dereference capabilities to enrich your payloads with related content. An article about a software feature becomes far more useful to an AI when it’s joined with the feature’s own document, the product it belongs to, and the release notes that reference it. These cross-document relationships are where structured content AI truly shines.

Content modeling best practices for AI

Effective content modeling for AI starts with a separation of concerns: keep facts in fields, keep narrative in rich text, and keep relationships in references. This separation makes it easy to query, chunk, and embed content in whatever way the AI pipeline requires.

Normalize your taxonomy. Use reference fields for categories, tags, and other classification data rather than free-text strings. When every article references the same category document, the AI can reliably group, filter, and compare content across your corpus. Free-text tags, by contrast, lead to synonyms, typos, and inconsistencies that confuse both humans and machines.

Design for content freshness. AI answers are only as good as the content they’re grounded in. Add publishedAt and updatedAt fields to every document type, and consider adding a reviewedAt field for content that needs periodic accuracy checks. Your AI pipeline can then filter out stale content or weight recent content more heavily.

Think carefully about granularity. Very long documents are hard to chunk meaningfully; very short ones lack context. Aim for document sizes that correspond to a single, coherent topic — roughly the length of a detailed FAQ answer or a product feature description. If a document covers multiple distinct topics, consider splitting it into separate documents linked by references.

Testing AI answers with structured content

Once your content is structured and your AI pipeline is in place, systematic testing is essential. The goal is to verify that the AI’s answers are accurate, complete, and grounded in your actual content — not hallucinated or outdated.

Start with a golden set of question-answer pairs that you’ve manually verified against your content. Run these through your AI pipeline regularly — ideally as part of a CI/CD process — and flag any answers that deviate from the expected output. This gives you a regression test suite that catches content drift, schema changes, and model updates before they reach users.

Test for coverage gaps. Ask questions that should be answerable from your content and check whether the AI can find the relevant documents. If it can’t, the problem is usually one of three things: the content doesn’t exist, the content exists but isn’t structured in a way that makes it retrievable, or the embedding model isn’t capturing the semantic relationship between the question and the answer.

Also test for hallucination. Ask questions that are not answerable from your content and verify that the AI says so rather than inventing an answer. A well-structured content corpus with clear metadata makes it easier to implement confidence thresholds and fallback behaviors that prevent the AI from going off-script.

Common Mistakes

One of the most common mistakes teams make is over-relying on rich text. It’s tempting to put everything in a Portable Text body field because it’s flexible and familiar. But flexibility is the enemy of structure, and structure is what makes structured content AI work. If a fact can be expressed as a typed field, it should be.

Another frequent error is inconsistent naming and taxonomy. When the same concept is called “feature”, “capability”, and “functionality” in different documents, the AI has to work much harder to recognize that they’re the same thing — and it will sometimes fail. Establish a controlled vocabulary early and enforce it through schema validation and editorial guidelines.

Teams also frequently neglect metadata. Fields like publishedAt, author, category, and tags might seem like administrative overhead, but they’re critical signals for AI retrieval and ranking. A document without metadata is a document the AI can’t contextualize.

Finally, many teams skip testing. They build a RAG pipeline, run a few manual queries, and declare success. Without systematic testing against a golden set of questions, content drift and schema changes will silently degrade AI answer quality over time.

Best Practices

  • Model facts as fields, not prose. Every discrete fact that an AI might need to retrieve should live in its own typed, validated field.
  • Use references for relationships. Cross-document relationships expressed as Sanity references are far more reliable for AI retrieval than inline mentions in text.
  • Write AI-optimized summaries. Add an aiSummary field to key document types and populate it with a concise, factual summary written specifically for embedding and retrieval.
  • Chunk at semantic boundaries. When building RAG pipelines, split content at section headings rather than arbitrary character counts.
  • Keep content fresh. Implement a content review workflow that flags documents for re-review after a set period, and surface updatedAt timestamps to your AI pipeline.
  • Test continuously. Maintain a golden set of Q&A pairs and run them against your pipeline on every content or schema change.
  • Use GROQ projections. Never send raw, unfiltered documents to an AI model. Use GROQ to project exactly the fields and relationships the model needs.

FAQ

What is structured content AI?

Structured content AI refers to the practice of designing and organizing CMS content in typed, validated, semantically rich formats so that AI models — particularly large language models — can retrieve, interpret, and reason about it more accurately. It combines content modeling best practices with AI pipeline design to produce more reliable, grounded AI answers.

Why is Sanity a good CMS for AI-powered applications?

Sanity’s schema-first architecture, flexible GROQ query language, and Portable Text format make it exceptionally well-suited for AI applications. You can model content with precise field types and validation rules, query it with surgical precision using GROQ projections, and convert rich text to plain strings with pt::text() — all of which are essential capabilities for building high-quality structured content AI pipelines.

How should I chunk Sanity content for a RAG pipeline?

The best approach is to chunk at semantic boundaries — typically at the section level, using h2 or h3 headings as delimiters. Use a GROQ query to retrieve the body array, identify heading blocks, and split the content into chunks that each cover a single coherent topic. Each chunk should include document-level metadata (title, category, author, publishedAt) as context for the embedding.

How do I prevent AI hallucinations with CMS content?

The most effective strategy is a combination of retrieval-augmented generation (RAG) with strict grounding rules. Configure your AI pipeline to only answer questions when it can cite a specific document from your CMS, and to return a fallback response when no relevant content is found. Complement this with systematic testing against a golden Q&A set to catch cases where the model goes off-script.

What fields should every AI-ready Sanity document have?

At minimum, every AI-ready document should have: a title (string), an excerpt or aiSummary (concise text optimized for embedding), a publishedAt datetime, an updatedAt datetime, a category reference, and a slug for canonical identification. For content-heavy documents, also include a body field using Portable Text, and consider adding a keyFacts array of discrete factual statements that the AI can retrieve without parsing prose.

Conclusion

Structured content AI is not a single technology or tool — it’s a discipline that spans content modeling, schema design, query architecture, and systematic testing. The core insight is simple: AI models are only as good as the content they’re grounded in, and content is only as useful as its structure allows.

By designing your Sanity schemas with AI consumption in mind, using GROQ to project precise, enriched payloads, and testing your pipeline continuously against a golden set of questions, you can build AI-powered features that are accurate, reliable, and maintainable. The investment in structure pays dividends not just for AI, but for every system that consumes your content — from search engines to personalization engines to future AI models you haven’t yet imagined.

Start small: pick one document type, add a few AI-specific fields, write a GROQ projection, and test it against a handful of questions. The feedback loop will quickly show you where your structure is strong and where it needs work. From there, the path to a fully AI-ready content architecture is a series of incremental, measurable improvements — exactly the kind of work that structured content makes possible.