Sub topic 10
Why robots.txt is a request, not a lock
This chapter assumes you can read a robots.txt file, know the crawler tokens from earlier chapters (GPTBot, Google-Extended, ClaudeBot and the rest), and can use curl and read short Python scripts. You will learn what robots.txt can and cannot do. That tells you when it is enough and when you need the server-side measures in the next chapter.
What "advisory" means
The Robots Exclusion Protocol (standardised as RFC 9309) is a convention. A site publishes rules at /robots.txt. A crawler fetches the file, reads the group that matches its user agent token, and decides whether to follow it. Nothing in HTTP forces that decision. Your web server answers a request for /members/report.html the same way whether or not the crawler consulted robots.txt first.
The protocol works because large operators have reasons to comply. They want to avoid legal disputes, keep their reputation, and keep site owners' goodwill. Major operators such as OpenAI, Google, Anthropic and Apple publish documentation saying their named crawlers honour robots.txt. A crawler that ignores the file, or one run by an operator who does not care about the convention, can still fetch your pages.
The protocol has no enforcement mechanism. A crawler's compliance is a property of that crawler's code and operator, not of your file.
A compliant crawler is just code that checks first
The check is a few lines in the crawler. This sketch uses the same standard-library parser you used for testing. The parser only answers a question. The decision to ask it, and to act on the answer, belongs to the crawler's author.
from urllib.robotparser import RobotFileParser
RULES = """\
User-agent: GPTBot
Disallow: /
User-agent: *
Allow: /
"""
parser = RobotFileParser()
parser.parse(RULES.splitlines())
def may_fetch(agent: str, url: str) -> bool:
"""Return True if robots.txt allows this agent to fetch the URL."""
return parser.can_fetch(agent, url)
url = "https://example.com/articles/guide"
for agent in ["GPTBot", "SomeOtherBot"]:
verdict = "fetch" if may_fetch(agent, url) else "skip"
print(f"{agent}: {verdict}")
# GPTBot: skip
# SomeOtherBot: fetchA scraper that never calls may_fetch, or calls it and ignores the result, is not stopped by anything in your file.
Where the protocol stops
Non-compliant and unnamed crawlers
Rules apply by user agent token. If a crawler is not in your file, it falls under User-agent: *. New AI crawlers appear regularly, so a list of named Disallow groups is always a little behind. A crawler may also choose to ignore the file entirely. In both cases robots.txt gives you nothing.
Spoofed user agents
The User-Agent header is text that the client writes. A scraper can send a browser string, or it can send the string of a well-known crawler. Spoofing matters in both directions:
- A scraper claiming to be a browser avoids every rule you wrote for named AI crawlers.
- A scraper claiming to be a search crawler you want (for example, one you allowed in order to appear in AI search) may be treated better than it deserves.
You can see how little the header proves by sending one yourself. This request claims to be GPTBot but comes from your own machine:
curl -sI -A "Mozilla/5.0 (compatible; GPTBot/1.1; +https://openai.com/gptbot)" \
https://example.com/ | head -n 1If your server blocks by user agent string alone, it will reject this request. It would also accept the same request with the string changed to Mozilla/5.0. For that reason a user agent rule on the server is a speed bump for honest crawlers that ignore robots.txt. It is not protection against a determined scraper.
User-initiated fetchers
Some agents fetch a page because a person asked an assistant to read a specific URL. ChatGPT-User is the example from earlier in this tutorial. Operators may treat these fetches as an extension of a user's own browsing, and OpenAI's documentation says robots.txt rules may not apply to such actions. Check each operator's current documentation for how its user-initiated agents behave. Do not assume a Disallow rule stops them. If you need a page to be unavailable to everyone, including a user's assistant, you need access control.
Content already collected
Robots.txt controls future requests. Adding Disallow: / for GPTBot today does not remove pages that were fetched last year, and it does not by itself remove them from a dataset already built. Operators may have their own processes for removal or for honouring changes at the next crawl. Treat the file as a forward-looking opt-out.
Robots.txt is public
Anyone can read https://example.com/robots.txt. If you write Disallow: /private-launch-plan/, you have published the path of something you wanted hidden. Keep sensitive paths out of the file and protect them with authentication instead.
Blocking crawling is not blocking indexing
A Disallow rule stops a compliant crawler from fetching a URL. It does not instruct anyone to forget the URL. A search engine may still list a blocked URL, without a description, if other pages link to it. To keep a page out of search results, the crawler has to be able to fetch the page and see a noindex directive. If robots.txt blocks the fetch, the directive is never seen. Do not combine the two on the same URL and expect both to work.
What a missing or broken file means
Crawlers also have to decide what to do when they cannot read the file. RFC 9309 sets these defaults, and large crawlers generally follow them:
| What the crawler receives | What it does |
|---|---|
| 200 with rules | Applies the rules |
| 404 or another 4xx | Treats the file as absent and may crawl everything |
| 5xx or a network error | Assumes complete disallow for a time, then retries |
| Very large file | May read only the first part, 500 KiB at minimum, and ignore the rest |
Three consequences follow. A typo in the path or a redirect to an HTML page can leave your rules unread, and the result is open access. A server error on /robots.txt can make a compliant crawler stop crawling your whole site until it recovers. Crawlers cache the file, often for up to 24 hours, so a change takes time to reach them.
Rules are also per host. https://example.com/robots.txt does not cover https://blog.example.com/ or http://example.com:8080/. Each subdomain and protocol-port combination needs its own file.
Choosing the right tool for each goal
Match the mechanism to what you need.
| Goal | Mechanism | Why |
|---|---|---|
| Tell honest operators not to train on public pages | robots.txt group per training token | Low cost, and major operators document compliance |
| Keep a page out of search results | `noindex` meta tag or `X-Robots-Tag` header, with the page crawlable | Crawling and indexing are separate |
| Stop requests from an unwanted crawler that claims its real identity | Server rule on the User-Agent header | Works on honest bots that ignore robots.txt |
| Stop a scraper that disguises itself | Rate limits, bot management, IP verification | The header cannot be trusted |
| Keep content private | Authentication | Only authentication denies access to everyone |
Verifying what is live
Because a broken file silently turns into open access, check the file the way a crawler would. Confirm the status code, the content type, and the body:
# Expect HTTP 200 and a text/plain content type
curl -sI https://example.com/robots.txt | head -n 5
# Confirm there are no redirects to an HTML page
curl -sIL -o /dev/null -w "%{http_code} %{url_effective}\n" https://example.com/robots.txtThen compare behaviour with your intent in your logs. If a token you disallowed still appears in requests for disallowed paths after the cache period, that crawler is not complying, or the requests come from someone else using its name. The monitoring chapter shows how to count and inspect those requests.
Common errors
- Treating
Disallowas access control and listing sensitive directories in a public file. - Expecting a rule for one token to cover another.
GPTBotandOAI-SearchBotare separate groups, as areGoogle-ExtendedandGooglebot. - Blocking a URL in robots.txt and adding
noindexto the same page, so the directive is never read. - Forgetting subdomains, which need their own file.
- Assuming a deployed change takes effect immediately, when crawlers may hold a cached copy for up to a day.
- Trusting the
User-Agentheader as proof of identity.
Summary
Robots.txt expresses your policy in a form that cooperating crawlers read and follow. It does not authenticate the crawler, block the request, or undo past collection. Use it for honest operators, and use server-side enforcement and access control for anything it cannot guarantee.
Exercise
Your robots.txt contains "User-agent: GPTBot" followed by "Disallow: /". A week later your access log shows requests to /articles/ with a user agent string containing "GPTBot". Give two different explanations that do not involve OpenAI's crawler ignoring your rule, and one check you would run for each.
Show answer
First, the crawler may have the old file cached. Crawlers often cache robots.txt for up to 24 hours, so check the request timestamps against the time you deployed the change, and confirm with curl that the live file returns 200 with the expected rules. Second, the request may be spoofed by a different client that copies the GPTBot string. Check the source IP address against the IP ranges the operator publishes for its crawler. Requests from outside those ranges are not the real crawler. If neither explains it, you can treat the traffic as non-compliant and block it on the server.
Exercise
A page is blocked in robots.txt for all crawlers, and you also added a noindex meta tag to it. The page still shows up in a search engine's results with no description. Why, and how would you fix it if you want it out of results?
Show answer
The Disallow rule prevents the crawler from fetching the page, so it never sees the noindex tag. The search engine can still list the URL based on links from other pages. To remove it from results, remove the Disallow rule so the crawler can fetch the page and read noindex, then add the rule back after the page has dropped out of the results if you still want it blocked from crawling. Authentication is the more reliable choice if the page must not be reachable at all.