Licensing, Consent, and Data-Use Signals › robots.txt and the Robots Exclusion Protocol
Language AI HandbookAll chapters robots.txt was introduced in 1994 and standardised as RFC 9309 in September 2022. The standard sets out path matching, user-agent groups and fetch handling. A parser can depart from those rules, as the CPython comparison below illustrates. Record which parser and version processed each check.
What RFC 9309 specifies
RFC 9309 defines how a crawler interprets a fetched rules file and what it should do when the fetch fails.
- Groups. Consecutive
User-agentlines can name several agents in one group. Matching is case-insensitive. Combine groups that match the crawler's product token and use the wildcard group when there is no explicit match. - Patterns.
*matches zero or more characters, and$anchors the end of the match. Matching accounts for percent encoding. - Precedence. Use the matching rule with the most octets. Prefer
Allowwhen an allow and a disallow rule are equivalent. - Size. If the crawler imposes a parsing limit, the limit must be at least 500 KiB.
- Status handling. A 4xx response can indicate an unavailable file, in which case crawling is allowed under the protocol. A server or network error makes the file unreachable, so the crawler initially assumes complete disallow.
- Caching. The standard recommends a cache lifetime of at most 24 hours unless the file is unreachable.
The CPython 3.11 implementation uses the first matching rule in file order within the chosen group. The example below compares that implementation with the RFC's longest-match rule on a few ASCII paths.
PythonIn [3]Expand
import hashlib
import json
import re
from dataclasses import dataclass, field, fields, replace
from enum import Enum
from typing import Optional
from urllib.robotparser import RobotFileParser
import numpy as np
import pandas as pdThis demonstration takes ASCII paths and one crawler product token. It handles basic groups, wildcards and simple allow/disallow patterns. It skips URL normalization, percent-encoding, status handling and caching. Equivalent tied patterns favor Allow; for distinct equal-length patterns the demonstration keeps the first.
PythonIn [4]Expand
def parse_robots(text):
"""Split a robots.txt file into groups of user agents and rules."""
groups = []
current = None
saw_rule = False
for raw_line in text.splitlines():
line = raw_line.split("#", 1)[0].strip()
if not line or ":" not in line:
continue
field, _, value = line.partition(":")
field = field.strip().lower()
value = value.strip()
if field == "user-agent":
# An empty rule still ends the user-agent block.
if current is None or saw_rule:
current = {"agents": [], "rules": []}
groups.append(current)
saw_rule = False
current["agents"].append(value.lower())
elif field in {"allow", "disallow"} and current is not None:
saw_rule = True
if value:
current["rules"].append((field == "allow", value))
return groupsThe second function turns a pattern into a regular expression and applies the longest-match rule.
PythonIn [5]Expand
def pattern_to_regex(pattern):
anchored = pattern.endswith("$")
body = pattern[:-1] if anchored else pattern
regex = re.escape(body).replace(r"\*", ".*")
return regex + ("$" if anchored else ".*")
def rule_matches(pattern, path):
return re.fullmatch(pattern_to_regex(pattern), path) is not None
def robots_allowed(groups, user_agent, path):
"""Return (allowed, winning_pattern) for the ASCII examples below."""
ua = user_agent.split("/")[0].lower()
specific = [g for g in groups if ua in g["agents"]]
wildcard = [g for g in groups if "*" in g["agents"]]
chosen = specific or wildcard # a specific group outranks the wildcard
if not chosen:
return True, None
rules = [rule for group in chosen for rule in group["rules"]]
matches = [
(len(pattern), allow, pattern)
for allow, pattern in rules
if rule_matches(pattern, path)
]
if not matches:
return True, None
longest = max(length for length, _, _ in matches)
tied = [
(allow, pattern)
for length, allow, pattern in matches
if length == longest
]
first_allow, first_pattern = tied[0]
for allow, pattern in tied:
if allow and pattern == first_pattern:
return True, pattern
return first_allow, first_patternNow compare CPython’s standard library against the longest-match demonstration on six crawler-path pairs.
PythonIn [6]Expand
demo_robots = """
# A publisher that allows almost everything, except one section.
User-agent: *
Allow: /
Disallow: /news/
User-agent: GPTBot
User-agent: ClaudeBot
Disallow: /
"""
groups = parse_robots(demo_robots)
stdlib = RobotFileParser()
stdlib.parse(demo_robots.strip().splitlines())
stdlib.modified() # record that the file was just fetchedPythonIn [7]Expand
comparison = []
for agent in ["MyResearchBot/0.1", "GPTBot/1.2"]:
for path in ["/", "/about", "/news/2025/story.html"]:
comparison.append(
{
"crawler": agent,
"path": path,
"stdlib": stdlib.can_fetch(
agent, "https://publisher.example" + path
),
"rfc9309": robots_allowed(groups, agent, path)[0],
}
)
comparison = pd.DataFrame(comparison)| crawler | path | stdlib | rfc9309 | |
|---|---|---|---|---|
| 0 | MyResearchBot/0.1 | / | True | True |
| 1 | MyResearchBot/0.1 | /about | True | True |
| 2 | MyResearchBot/0.1 | /news/2025/story.html | True | False |
| 3 | GPTBot/1.2 | / | False | False |
| 4 | GPTBot/1.2 | /about | False | False |
| 5 | GPTBot/1.2 | /news/2025/story.html | False | False |
The implementations agree on five of the six cases. For MyResearchBot requesting /news/2025/story.html, CPython 3.11 allows the request because Allow: / is the first matching rule. The RFC's matching rule disallows it because Disallow: /news/ is the longer match. If you reverse the two directives in the wildcard group, both deny the request in this example.
PythonIn [9]Expand
robot_cases = comparison.assign(
case=comparison["crawler"].str.split("/").str[0]
+ " @ "
+ comparison["path"]
).set_index("case")[["stdlib", "rfc9309"]]VisualizationOut [10]Expand

Record which parser and matching rules the crawler uses. For the research-crawler example above, changing parser changes the decision on the same file. Keeping the raw file and parser version gives a reviewer a way to reproduce the decision.
Crawling is not training
The Robots Exclusion Protocol describes how a crawler obtains the origin's rules and checks them for its product token and request path. It does not establish permission to use a retained copy for training. Record the basis for that use separately.
If your dataset policy considers changes to robots.txt, give it two observations to compare:
- At crawl time, apply the rules for the crawler and path. Archive the result, the fetched rules and the observation time.
- At dataset construction time, check the same origin, crawler and path again. Archive the second observation and compare it with the first.
- If the rule now disallows the path, preserve both observations. Route the source for review of the use basis and any applicable reservation, and use the lineage record to locate the affected copies.
Record the origin that served robots.txt and the user agent you checked. In a hosted-newsletter example, the platform may publish the file for a domain where a writer contributes content. Keep a separate record of what the platform controls and what the writer has authorized. Use a separate licence or use-specific signal to record conditions such as research-only use.
AI-specific user agents
Operators document product-specific controls for crawling and downstream use. Record the named token and the operation it covers:
| Token | Operator | What it controls |
|---|---|---|
GPTBot | OpenAI | Collection for OpenAI model training |
Google-Extended | Use of crawled content for covered generative AI training and grounding outside Google Search | |
CCBot | Common Crawl | Inclusion in the Common Crawl corpus |
ClaudeBot | Anthropic | Collection for Anthropic model training |
Applebot-Extended | Apple | Use of content in Apple foundation model training |
Meta-ExternalAgent | Meta | Collection for uses including foundation-model training and direct content indexing |
Google documents Google-Extended as a product token that controls downstream training and grounding for covered products. The token leaves inclusion and ranking in Google Search unaffected. Common Crawl documents CCBot as its collection crawler. Its collection rules do not settle a downstream user's training permission. Meta lists both training and direct indexing as uses for data collected by Meta-ExternalAgent. Store the token and purpose with the observation so you can distinguish those cases.
Longpre and colleagues' 2024 study Consent in Crisis: The Rapid Decline of the AI Data Commons measured a rise in restrictions between 2023 and 2024. The authors report that their fully restricted category reached more than 5% of all C4 tokens and more than 28% of tokens from a selected subset of actively maintained, critical C4 sources. Those percentages describe their corpus and restriction criteria. For your own mixture, compare the tokens that pass Quality Filtering with the tokens that also pass the data-use policy. Break out the difference by source and language before estimating how much data you would need to replace.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!