DEV Community

Cover image for How to Create an LLM.txt File to Manage AI Crawler Access
Matt Joshi
Matt Joshi

Posted on

How to Create an LLM.txt File to Manage AI Crawler Access

So you've heard about LLM.txt files and want to control how AI crawlers interact with your website. Let me walk you through actually generating one that works.

First, what exactly is an LLM.txt file? Think of it as robots.txt but specifically for large language models. It tells AI crawlers which parts of your site they can access and how they should process your content. It's becoming essential as more AI systems scrape the web.

Here's a basic structure for your LLM.txt:

User-agent: *
Allow: /blog/
Allow: /docs/
Disallow: /private/
Disallow: /api/internal/

Rate-limit: 10 requests per minute
Max-tokens: 4096
Enter fullscreen mode Exit fullscreen mode

But you can go deeper. Let me show you how to generate one dynamically with Node.js:

const fs = require('fs');
const path = require('path');

function generateLLMTxt(config) {
  let content = '';

  // Add user agents
  config.agents.forEach(agent => {
    content += `User-agent: ${agent.name}\n`;
    agent.allowedPaths.forEach(p => content += `Allow: ${p}\n`);
    agent.disallowedPaths.forEach(p => content += `Disallow: ${p}\n`);
    content += '\n';
  });

  // Add rules
  if (config.rateLimit) {
    content += `Rate-limit: ${config.rateLimit}\n`;
  }
  if (config.maxTokens) {
    content += `Max-tokens: ${config.maxTokens}\n`;
  }

  return content;
}

const myConfig = {
  agents: [
    {
      name: 'GPTBot',
      allowedPaths: ['/public/', '/blog/'],
      disallowedPaths: ['/admin/', '/drafts/']
    },
    {
      name: 'Claude-Web',
      allowedPaths: ['/docs/'],
      disallowedPaths: ['/api/']
    }
  ],
  rateLimit: '20 requests per minute',
  maxTokens: 8192
};

const llmTxt = generateLLMTxt(myConfig);
fs.writeFileSync('LLM.txt', llmTxt);
Enter fullscreen mode Exit fullscreen mode

The key insight? You want to be specific. Don't just block everything - that hurts your visibility. Instead, grant access to your valuable content while protecting sensitive areas.

For example, if you run a dev blog, allow crawlers to index your tutorials but block draft posts and internal tools. This way AI models can still reference your work without exposing unfinished content.

I've been using the SERPSpur LLM.txt Generator to streamline this process. It handles the syntax validation and lets me preview exactly how different AI agents will interpret my rules. The configuration interface makes it easy to toggle permissions without manually editing files.

One thing I learned the hard way: always test your LLM.txt against actual crawlers. Some AI companies have specific requirements. For instance, Anthropic's Claude-Web expects certain header formats that aren't standard.

Here's a quick testing snippet:

curl -I -H "User-Agent: GPTBot" https://yoursite.com/LLM.txt
Enter fullscreen mode Exit fullscreen mode

If you get a 200 with your rules, you're good. If it's 404, check your file placement - it must be in the root directory.

The bottom line: LLM.txt files aren't complicated once you understand the pattern. Start simple, test thoroughly, and iterate based on what crawlers actually hit. Your content strategy will thank you when AI systems start properly respecting your boundaries.

Top comments (2)

Collapse
 
emma-watson3 profile image
Emma Watson

Great breakdown! One thing I'd add is that the dynamic generation approach works well, but you might also want to handle the versioning aspect. I've found it helpful to include a # LLM.txt v1.0 comment at the top and track changes in git so you can rollback if a crawler starts behaving differently after a rule update.

Also, for anyone dealing with multiple domains or subdomains, consider using environment variables in your Node script to switch between production and staging rules—saved me from accidentally exposing internal docs on a live site. The curl test snippet is spot on; I'd also recommend checking the response headers for cache-control to ensure crawlers aren't served stale rules.

Collapse
 
juliatheron profile image
Julia Theron

This is such an underrated tip. I used to overlook it until a production bug taught me the hard way—now it's second nature. Thanks for sharing!