GEO Pilot: we optimise your site for AI search in 30 days, $999.See what is included →

Technical

How to test your robots.txt for AI bots with Python (and where it misleads you)

We ran seven small robots.txt files through Python's standard parser, 17 checks in all. Some results match what you expect. Three do not, and each could make you think an AI bot is blocked or allowed when it is not.

Nitesh Dan CharanBy , Founder · Updated 3 December 2026 · 6 min read
How to test your robots.txt for AI bots with Python (and where it misleads you)
Key takeaways
  • Python's urllib.robotparser is a fast first check for AI crawler rules, but it is not the parser any crawler uses. In our seven file test it ignored a wildcard rule, applied rules in file order and read only the first of two groups for the same bot.
  • OpenAI documents separate bots for search, training and user actions. As of the page we read in October 2026, OAI-SearchBot and GPTBot obey robots.txt, and ChatGPT-User may not.
  • Use the parser to catch obvious mistakes, then confirm with the vendor's documentation and your server logs. A parser result is a hint, not proof of what a crawler will do.

Can you test robots.txt for AI crawlers with Python?

Yes. Python ships with urllib.robotparser, which reads a robots.txt file and answers a simple question: may this user agent fetch this URL? It is fast, free and good for catching obvious mistakes such as a stray Disallow slash. It is also a simplified parser, and in our tests it gave answers that a real crawler would not always give. This article shows what we tested, what came out, and how to use the tool without being fooled.

We ran this on 24 October 2026 with Python 3.11.15. We wrote seven small robots.txt files, each built to test one behaviour, and ran 17 checks across them. We did not test a live site, and we did not look at server logs. Everything below is about the parser, not about what ChatGPT, Perplexity or Google does at crawl time. If you want the rules for what to allow, read which AI crawlers to allow in robots.txt first, then come back to test your file.

Which AI bots should you test?

OpenAI's crawler overview, which we read in October 2026, lists four user agents. OAI-SearchBot is used to surface sites in ChatGPT search features. GPTBot crawls content that may be used to train generative AI foundation models. its ads bot, listed as OAI AdsBot, checks pages submitted as ads on ChatGPT. ChatGPT-User handles user initiated actions in ChatGPT and Custom GPTs.

The page makes three points that matter for testing. Each setting is independent, so allowing one does not allow another. OAI-SearchBot and GPTBot obey robots.txt. For ChatGPT-User, the page says that because actions are user initiated, robots.txt rules may not apply. It also says a robots.txt update can take about 24 hours to take effect for search results. That means a parser test tells you what the file says, not what the system has already picked up.

User agentWhat OpenAI says it doesDoes robots.txt apply?
OAI-SearchBotSurfaces websites in ChatGPT search featuresYes. Opting out means not shown in ChatGPT search answers
GPTBotCrawls content that may be used to train foundation modelsYes. Disallowing signals content should not be used for training
ChatGPT-UserUser initiated actions in ChatGPT and Custom GPTsRules may not apply, per the page
OAI AdsBotChecks safety of pages submitted as adsNot stated on the page we read

What did we test, and what happened?

Each test is small on purpose. Here are the seven files and the results, in the order we ran them.

TestFile in plain wordsResult in Python 3.11.15
AAll bots blocked from /private/. GPTBot blocked from everythingGPTBot blocked on the blog and private paths. OAI-SearchBot, ChatGPT-User and Googlebot allowed on the blog, blocked on /private/
BDisallow /blog/ first, then Allow /blog/public/A public page was reported blocked
CAllow /blog/public/ first, then Disallow /blog/The same public page was reported allowed
DDisallow /*.pdf$ (wildcard and end anchor)A PDF URL was reported allowed. An HTML URL was allowed
ETwo separate GPTBot groups, one blocking /a/, one blocking /b//a/ blocked, /b/ allowed
FGroup written as gptbot in lower case, disallow everythingGPTBot reported blocked, so names are not case sensitive
GBlock all bots, then give OAI-SearchBot its own group that allows everythingOAI-SearchBot allowed, GPTBot blocked

Where does the parser mislead you?

Rule order changes the answer (tests B and C)

In test B the Disallow came first and the more specific Allow came second. The parser reported the public page blocked. Reverse the two lines and it reports the page allowed. So the parser applies the first rule that matches, in file order. Google documents a different approach for its own crawlers, where the most specific matching rule wins, and the standard published as RFC 9309 describes a longest match approach. We did not read the RFC again during this test, so check it before you rely on our summary. The practical point stands: the same file can pass in one parser and fail in another, so do not treat a single result as final.

Wildcards are ignored (test D)

The rule that blocks every PDF uses a star and a dollar sign. Major crawlers support those characters. Python's parser read the rule literally, so it never matched a real PDF path, and it reported the PDF as allowed. If your file blocks file types with wildcards, a Python test will say your PDFs are open when a real crawler may treat them as closed.

Only the first group is read (test E)

Test E repeated the same user agent in two groups. The parser blocked the path in the first group and allowed the path in the second. Many people write robots.txt files by appending a new block for the same bot after an old one, for example when a plugin and a person both edit the file. A parser that stops at the first group would report a safe state that a more standard parser would not. We are describing the standard library behaviour we saw, not claiming how any particular crawler merges groups.

How to read this evidence. Seven files and 17 checks on one Python version is a small test. It shows specific behaviours of one tool. It does not show how any crawler treats your site. Test your own file, and when stakes are high, use the vendor's documentation and your own logs as the final word.

What does a safe testing routine look like?

  1. Fetch your live robots.txt and save a dated copy. Do not test an edited local copy and assume it is deployed.
  2. Write down the intended outcome for each bot and key path in a small table: allowed or blocked, and why.
  3. Run the Python check for each bot and path. Flag every result that differs from your table.
  4. For any flagged result, remove wildcards and duplicate groups where you can, put specific Allow lines before broader Disallow lines, and test again.
  5. Wait for the vendor's stated delay. OpenAI says about 24 hours for search. Then check the vendor documentation and your server logs for the bot's visits.
  6. Repeat after any CMS, plugin or CDN change, because those often rewrite robots.txt.

How does this fit with the other ways to check access?

The parser answers one question: what does this file permit for this name? It does not tell you whether a firewall or CDN is blocking the bot before robots.txt is even read, whether the pages render for a crawler that does not run scripts, or whether your sitemap lists the right URLs. For those, use the free AI Crawler Access Checker, and generate a clean file with the AI Crawler Robots.txt Generator. Our guide to GEO for JavaScript and headless sites covers the rendering side.

If you are still deciding which bots to allow, remember the trade off OpenAI describes. Blocking OAI-SearchBot means not appearing in ChatGPT search answers. Blocking GPTBot is a separate choice about training. They are independent, so make the decision for each on purpose.

What should you do next?

Open your robots.txt today and read it as a list of names and paths. Remove duplicate groups, avoid clever wildcards unless you need them, and write down your intended policy for search bots, training bots and user action bots. Then test it. If you would rather have the access fixes and the checks done for you, the crawler access check is part of Week 1 of the GEO Pilot, and the fixes follow in Week 2.

What the research says

Evidence behind this page

Checked figures from published studies, each with its source and date. More in our AI search statistics.

7.8%

Only about 37% of the top 10,000 domains had a robots.txt file, and GPTBot was disallowed in 7.8% of top domains' robots.txt files (Google-Extended 5.6%, ClaudeBot under 5%).

Sample: Top 10,000 domains (Cloudflare Radar). Period: As of publication

Primary sourceCloudflareJuly 2025
38,065:1

In July 2025 Anthropic's crawlers made about 38,066 crawls per referred visit, OpenAI's 1,091 and Perplexity's 195.

Sample: Cloudflare network traffic. Period: January – July 2025

Primary sourceCloudflareAugust 2025
48% / 24%

By end of 2023, 48% of the most widely used news websites across ten countries blocked OpenAI's crawlers and 24% blocked Google-Extended (US: 79% blocked OpenAI).

Sample: Top 15 news sites in each of 10 countries. Period: 2023

Primary sourceReuters Institute for the Study of JournalismFebruary 2024

Cite this guide

You may quote this page with a link. Where a figure comes from another study, please credit that study too.

GrowingAI. (2026, 18 October 2026). How to test your robots.txt for AI bots with Python (and where it misleads you). https://thegrowingai.com/test-robots-txt-for-ai-bots-with-python/

Our clients

Businesses we work with

Real businesses we have worked with. We show their results only with the limits stated.

Quality Mascots Costumes logoRMS Stonex logoSudarshan Stoneix logo
Emtech Computers logo
Happy Home IC logo
Trade Like Master logo
One Percents logo
Arc Studio logo

FAQ

Questions people ask

Is Python's robots.txt parser the same as Google's?

No. In our test it applied rules in file order, ignored wildcard characters and read only the first of two groups for the same bot. Google documents its own parser behaviour, so use Google's tools to check Googlebot rules.

Does blocking GPTBot remove me from ChatGPT search?

According to OpenAI's crawler overview, GPTBot relates to training and OAI-SearchBot relates to ChatGPT search. The settings are independent. Check the current page before you decide.

How long does a robots.txt change take to apply?

OpenAI says it can take about 24 hours from a robots.txt update for its search systems to adjust. Other vendors do not necessarily publish a figure.

Should I block ChatGPT-User?

OpenAI says robots.txt rules may not apply to it because the actions are user initiated. Do not count on robots.txt alone to control it.

Can the test file be wrong even if Python says allowed?

Yes. A firewall, a CDN rule or a login wall can block a bot before it reads robots.txt. Test access with a crawler checker and look at your logs.

Nitesh Dan Charan

Nitesh Dan Charan

Founder, GrowingAI

Nitesh is the founder of GrowingAI, a generative engine optimization (GEO) agency that helps brands get named and cited in AI answers on ChatGPT, Google AI Overviews, Gemini and Perplexity. He writes from client work in the UAE, USA and UK. Every guide is dated, sourced and reviewed before it is published. See our research standards.

Want this done for your site?

Send your site and five buyer questions. We test them in the major AI engines and send back a short, honest read.

  • Recorded baseline in five AI engines
  • Competitors named
  • Three first fixes, ranked

No card, no contract. Nitesh replies himself, usually the same working day. By sending, you agree we may contact you about this request (privacy policy).