X-robots http headers are more reliable: https://developers.google.com/search/docs/crawling-indexing/...
Regarding AI, it's a bit more tricky since it isn't going to abide by your rules. Cloudflare have tools: https://blog.cloudflare.com/ai-bots/
How effective these are though, IDK?