/ llmtxt.info

llms.txt in Ruby on Rails

Rails serves the public/ folder at the site root. Add llms.txt there, or generate it from a controller if the content is dynamic.

Last updated:

Two approaches

Rails can serve llms.txt two ways: a static file in public/ (simplest), or a controller action that builds the file from your data. Use the static file unless the content must reflect live records.

Method 1: static file in public/

Everything in public/ is served at the domain root. A file at public/llms.txt resolves to /llms.txt.

  1. Create the file: touch public/llms.txt
  2. Write your content (see the how-to guide):
# Your App Name

> One-sentence description of your app for LLM context.

## Core pages

- [Home](https://yourdomain.com/): what this app does.
- [Pricing](https://yourdomain.com/pricing/): plans and limits.
- [Docs](https://yourdomain.com/docs/): developer documentation.

Method 2: a controller action

To generate the file dynamically, add a route and a controller that renders plain text:

# config/routes.rb
get "/llms.txt", to: "llms#show"

# app/controllers/llms_controller.rb
class LlmsController < ApplicationController
  def show
    pages = Page.published.order(:title) # example data source
    body = "# Your App Name\n\n> Description of your app.\n\n## Core pages\n\n"
    body += pages.map { |p| "- [#{p.title}](#{page_url(p)}): #{p.summary}" }.join("\n")
    render plain: body, content_type: "text/plain"
  end
end

Serving static files in production

Verifying the setup

curl -sI https://yourdomain.com/llms.txt | grep -i content-type
# expect: content-type: text/plain

Using Laravel instead? See the Laravel guide. For a fuller export of page content, add llms-full.txt.

Sources