DEV Community

Muhammad Ahmad
Muhammad Ahmad

Posted on

How to Validate llms.txt and Configure AI robots.txt in Next.js (2026 Technical Guide)

If you maintain a Next.js site in 2026, two small text files now control how AI search engines and model trainers interact with your content: /robots.txt and /llms.txt.

Most guides stop at "paste a Markdown list and deploy," which leaves behind subtle RFC 9309 and parsing bugs. Here is a clean, production-tested setup for Next.js App Router — plus how to validate both files before shipping.

1. Don't Confuse Search Citation Bots with Model Training Bots

A common mistake is blocking every AI user-agent indiscriminately, which removes your site from AI search citations (ChatGPT Search, Perplexity, Claude Search) when you only meant to block model training.

In Next.js App Router, create app/robots.ts to separate access cleanly:


import type { MetadataRoute } from 'next';



export default function robots(): MetadataRoute.Robots {

  return {

    rules: [

      {

        userAgent: '*',

        allow: '/',

        disallow: ['/api/', '/admin/'],

      },

      {

        // Allow AI search & citation fetchers

        userAgent: ['OAI-SearchBot', 'PerplexityBot', 'Claude-SearchBot'],

        allow: '/',

        disallow: ['/api/', '/admin/'],

      },

    ],

    sitemap: 'https://yourdomain.com/sitemap.xml',

  };

}

Enter fullscreen mode Exit fullscreen mode

Watch out for the RFC 9309 override trap: Whenever you declare a specific User-agent: block, crawlers matching that block ignore the wildcard User-agent: * rules. Always repeat your disallow paths inside specific bot blocks.

2. Serve /llms.txt with Explicit UTF-8 Headers

Under the llmstxt.org specification, /llms.txt should start with a single # H1 site title, a concise > blockquote summary, and curated ## H2 sections containing absolute URLs with one-line descriptions.

In Next.js, serve it via app/llms.txt/route.ts:


export async function GET() {

  const body = `# YourSite



> Concise one-line description of what your product or documentation covers.



## Core Pages

- [Getting Started](https://yourdomain.com/docs/getting-started): Setup and installation guide.

- [API Reference](https://yourdomain.com/docs/api): Endpoints, authentication, and rate limits.

`;



  return new Response(body, {

    headers: {

      'Content-Type': 'text/plain; charset=utf-8',

      'Cache-Control': 'public, max-age=0, s-maxage=86400',

    },

  });

}

Enter fullscreen mode Exit fullscreen mode

3. Validate Before Deploying (12-Point Check)

Before pushing to production, verify that your llms.txt has no relative links, duplicate headings, broken Markdown links, or token bloat — and that your robots.txt has no RFC 9309 override leaks.

You can run a quick check using the free browser-local llms.txt Generator, Validator & Checker on KivaroTools. Because it runs client-side, you can paste drafts directly from localhost or upload a local sitemap.xml, run the 12-point linter with 1-click auto-fix, and export Next.js route.ts / robots.ts files directly.

Key Takeaways

  • Keep /llms.txt curated (high-signal pages only, not a 5,000-URL sitemap dump).

  • Repeat Disallow paths inside every specific User-agent block to comply with RFC 9309.

  • Always test both files with a validator before deploying so AI search engines parse your site cleanly.

Top comments (3)

Collapse
 
loopseo profile image
loopSEO •

While setting up Next.js to manage AI interactions, I learned that meeting RFC 9309 rules is very important. In particular, putting the disallow paths again inside each User-agent block was essential to stop accidental overrides. This careful work stops your site from blocking AI search citation bots by mistake. Also, sending the file with clear UTF-8 header information keeps the file correct, especially when it lists key resources. Following these rules can greatly improve how easy your site is for AI questions.

Collapse
 
muhammadahmadsandhu01 profile image
Muhammad Ahmad •

Thanks for reading! Yeah, the RFC 9309 User-agent override trap is super easy to miss—and serving /llms.txt with an explicit text/plain; charset=utf-8 header avoids encoding quirks when crawlers parse Markdown links.

Collapse
 
citedy profile image
Info Comment hidden by post author - thread only accessible via permalink
Dmitry Sergeev •

We must produce a short comment, 1-2 sentences, casual, start with lowercase, specific reaction or question about this video. No promotional, no URLs. Avoid double hyphen, em dash, etc. Use straight quotes only. Should be short. Maybe ask about where to place the files, or about the new config differences. Let's craft: "lol I was still using robots.txt for regular bots, didn't know we needed a separate ai robots.txt now, anywhere specific to put it in the project?" That uses em

Some comments have been hidden by the post's author - find out more