Sub topic 3
Testing your rules
This chapter assumes you can edit the robots.txt file at your site root, read a combined-format access log, run curl, and read basic Python. You should already know that each group in robots.txt starts with a User-agent line, and that a crawler follows the group that matches its name.
Testing your rules
Test a draft before you deploy it. Python's standard library includes urllib.robotparser, which applies the Robots Exclusion Protocol the way a well-behaved crawler does.
from urllib.robotparser import RobotFileParser
rules = """\
User-agent: GPTBot
Disallow: /
User-agent: OAI-SearchBot
Allow: /
User-agent: *
Allow: /
"""
parser = RobotFileParser()
parser.parse(rules.splitlines())
url = "https://example.com/articles/guide"
for agent in ["GPTBot", "OAI-SearchBot", "SomeOtherBot"]:
print(agent, parser.can_fetch(agent, url))
# GPTBot False
# OAI-SearchBot True
# SomeOtherBot TrueAfter deployment, check the live file. The -I flag shows the status line and headers:
curl -sI https://example.com/robots.txt | head -n 5
curl -s https://example.com/robots.txtExpect a 200 status and a text content type. A 404 means no rules exist, so crawlers may fetch everything.
Why robots.txt is a request, not a lock
robots.txt states your preferences. The protocol does not force any crawler to follow them. A crawler can ignore the file, and any client can send a User-Agent header that claims to be GPTBot. Treat the file as a published policy, not a security control. Put private content behind authentication.
Enforcing blocks on the server and verifying crawlers
To enforce a block, match the User-Agent header in your web server. This stops crawlers that send an honest name but ignore robots.txt. It does not stop a spoofed header. For that, verify the requester's IP address against the vendor's published ranges or reverse-DNS guidance, if the vendor provides them. Check each vendor's current documentation first.
# In the http block
map $http_user_agent $block_ai_crawler {
default 0;
~*GPTBot 1;
~*ClaudeBot 1;
~*CCBot 1;
}
# In the server block
if ($block_ai_crawler) {
return 403;
}Reading logs to see who is crawling
Count requests per crawler in your access log to see which bots visit your site:
grep -Ei 'GPTBot|OAI-SearchBot|ChatGPT-User|ClaudeBot|PerplexityBot|CCBot' access.log \
| grep -Eio 'GPTBot|OAI-SearchBot|ChatGPT-User|ClaudeBot|PerplexityBot|CCBot' \
| sort | uniq -c | sort -rnThen look for blocked crawlers that keep fetching pages. Continued requests after a Disallow rule point to a crawler that ignores robots.txt, or to a spoofed user agent. Check the status field too: 403 responses confirm that your server rule works.
Keeping your policy up to date
AI crawler names change. Review your robots.txt and server rules every few months, compare them with each vendor's current crawler documentation, and add new bot names to your log filter when they appear.
Exercise
A robots.txt group reads User-agent: GPTBot followed by Disallow: /. What does parser.can_fetch("GPTBot", "https://example.com/") return?
Show answer
False. The Disallow: / rule blocks every path for GPTBot.