api/src/ai/tools/items/prompt.md
Perform CRUD operations on items within Directus collections
read: Query items with filtering/pagination/field selectioncreate: Add items with nested relationsupdate: Modify items with partial datadelete: Remove items by primary keys{ "fields": ["title", "status", "author.name", "categories.*"] }
For M2A relations: "sections.item:headings.title", "sections.item:paragraphs.body"
Core: _eq, _neq, _in, _nin, _null, _nnull, _lt, _lte, _gt, _gte, _between, _contains,
_icontains, _starts_with, _ends_with, _empty, _nempty Relations: _some, _none (O2M only) Logic: _and,
_or
{"status": {"_eq": "published"}}
{"title": {"_icontains": "keyword"}}
{"categories": {"_some": {"name": {"_eq": "News"}}}}
{"_or": [{"status": {"_eq": "published"}}, {"featured": {"_eq": true}}]}
{
"fields": ["title", "comments.text", "comments.author.name"],
"deep": {
"comments": {
"_filter": { "status": { "_eq": "approved" } },
"_sort": ["-date_created"],
"_limit": 5
}
}
}
✅ GOOD - Single with Relations:
{
"action": "create",
"collection": "posts",
"data": [
{
"title": "New Post",
"author": { "name": "John Doe", "email": "[email protected]" }, // Creates nested
"categories": [1, 2, { "name": "New Category" }], // Mix existing + new
"status": "draft"
}
]
}
✅ GOOD - Batch Create:
{
"action": "create",
"collection": "posts",
"data": [
{ "title": "Post 1", "author_id": 1 },
{ "title": "Post 2", "author_id": 2 }
]
}
❌ BAD - Missing Required Fields:
// Don't create without checking schema first
{ "title": "Post" } // Missing required fields like status
✅ GOOD - Update with Keys:
{
"action": "update",
"collection": "posts",
"keys": ["uuid-1", "uuid-2"],
"data": { "status": "published" }
}
✅ GOOD - Batch Update (Different Data):
{
"action": "update",
"collection": "posts",
"data": [
{ "id": "uuid-1", "title": "Updated Title 1" },
{ "id": "uuid-2", "title": "Updated Title 2" }
]
}
✅ GOOD - Relational Updates:
{
"action": "update",
"collection": "posts",
"keys": ["uuid-1"],
"data": {
"categories": {
"create": [{ "name": "New Category" }],
"update": [{ "id": 3, "name": "Renamed" }],
"delete": [5]
}
}
}
❌ BAD - Update Without Keys:
// Don't update without specifying which items
{
"action": "update",
"data": [{ "status": "published" }] // Will fail - no keys provided
}
✅ GOOD - Delete by Keys:
{
"action": "delete",
"collection": "posts",
"keys": ["uuid-1", "uuid-2"]
}
❌ BAD - Delete All (Dangerous):
// Never delete without keys - use query to get keys first
{
"action": "delete",
"collection": "posts" // Will fail - keys required
}
✅ GOOD - Singleton Read:
{
"action": "read",
"collection": "settings", // Singleton collection
"query": { "fields": ["site_name", "logo"] }
}
✅ GOOD - Singleton Update:
{
"action": "update",
"collection": "settings",
"data": { "site_name": "New Name" } // No keys needed for singleton
}
// Create with nested author
{"title": "Article", "author": {"name": "New Author"}}
// Link existing author
{"title": "Article", "author": "existing-uuid"}
// Remove relation
{"author": null}
// Link to existing comments
{"comments": [1, 5, 9]}
// Create/update/delete operations
{
"comments": {
"create": [{"text": "New comment"}],
"update": [{"id": 5, "text": "Updated"}],
"delete": [1, 9]
}
}
{
"sections": [
{ "collection": "headings", "item": { "text": "Title", "level": 1 } },
{ "collection": "paragraphs", "item": { "content": "Body text" } }
]
}
// Create with multiple languages
{
"title": "Main Title",
"translations": [
{"languages_code": "en-US", "title": "English Title", "content": "English content"},
{"languages_code": "fr-FR", "title": "Titre Français", "content": "Contenu français"}
]
}
// Read specific language
{
"fields": ["title", "translations.title", "translations.content"],
"deep": {
"translations": {
"_filter": {"languages_code": {"_eq": "fr-FR"}}
}
}
}
schema() first to discover collectionsschema(keys: ["collection"]) for field details based on users queryrelation.related_collections in field definitions when it's relevant to your taskcollection.singleton: true)fields to minimize payload sizelimit for large result sets (default: no limit)scehma(keys: ["collection"])Regular Collections: Require keys for update/delete, return arrays Singleton Collections: No keys needed, return single objects, auto-upsert behavior
Date: year(field), month(field), day(field), hour(field) Aggregate: count, sum, avg, min, max
{"filter": {"year(date_created)": {"_eq": 2024}}}
{"aggregate": {"count": ["*"], "sum": ["price"]}, "groupBy": ["category"]}
directus_* collections