How it works
Crawlers look for the file at yourdomain.com/robots.txt before they fetch anything else. Each group starts with a User-agent line naming a crawler, or an asterisk for all of them, followed by Disallow and Allow lines for paths. A Sitemap line can point crawlers to your XML sitemap.
What robots.txt does not do
Google's documentation says robots.txt is used mainly to avoid overloading your site with requests, and that it is not a way to keep a page out of Google. A blocked URL can still be indexed if other pages link to it; Google just can't read what is on it. To keep a page out of search results, use a noindex tag or put it behind a password.
robots.txt and AI search
Google says robots.txt rules for Googlebot are also how you control crawling for its AI features in Search, since they are part of Search. A separate token, Google-Extended, covers AI training and grounding in some of Google's other systems. Other AI companies publish the names of their own crawlers, which you can give their own group.