When exposing Ash actions as tools, access is governed by attribute visibility and the load option:
- Filtering/Sorting/Aggregation: Only public attributes (
public?: true) can be used. - Single-record lookup: Use
get_by on read tools to look up one record by filterable fields. - Arguments: Only public action arguments are exposed.
- Response data: Public attributes are returned by default.
- Loading data: Use the
load option to include relationships, calculations, or additional attributes (including private ones) in responses.
Key Distinction: Private attributes cannot be used for filtering, sorting, or aggregation, but they CAN be included in responses when using the load option.
tools do
# Returns only public attributes
tool :read_posts, MyApp.Blog.Post, :read
# Returns one post by ID instead of a list of results
tool :get_post_by_id, MyApp.Blog.Post, :read, get_by: :id
# Returns public attributes AND loaded relationships/calculations
# Note: loaded fields can include private attributes
tool :read_posts_with_details, MyApp.Blog.Post, :read,
load: [:author, :comment_count, :internal_notes]
end