Object Definition
Object Definition
Object files define business entities or database tables in YAML (or JSON). They are the foundation of your application's data model and are designed to be both human-readable and AI-friendly for automated code generation.
File Naming Convention: <object_name>.object.yml
The filename (without the .object.yml extension) automatically becomes the object's API name. This eliminates the need for a redundant name property inside the file.
Examples:
project.object.yml→ Object API name:projecttask.object.yml→ Object API name:taskcustomer_order.object.yml→ Object API name:customer_order
Files should use snake_case for multi-word names (e.g., project_tasks.object.yml).
1. Root Properties
| Property | Type | Required | Description |
|---|---|---|---|
label | string | Recommended | Human-readable label (e.g., "Project Task"). Defaults to capitalized filename if omitted. |
icon | string | Optional | SLDS icon string (e.g., standard:task). |
description | string | Optional | Internal description of the object. |
fields | Map | Required | Dictionary of field definitions. |
actions | Map | Optional | Dictionary of custom action definitions. |
ai_context | object | Optional | AI-friendly context for code generation and understanding. |
Note: The name property is no longer needed - it's automatically inferred from the filename.
1.1 AI Context (Optional)
The ai_context block provides semantic information to help AI tools understand the business purpose and usage patterns of your object. This improves code generation accuracy and enables intelligent suggestions.
| Property | Type | Description |
|---|---|---|
intent | string | Brief description of the object's business purpose. |
domain | string | Business domain (e.g., sales, project_management, hr). |
aliases | string[] | Natural language terms users might use to refer to this object. |
examples | object[] | Sample records showing typical data patterns. |
common_queries | string[] | Typical questions or searches users perform. |
2. Field Definitions
Fields are defined under the fields key. The key for each entry corresponds to the field's API name.
2.1 Common Properties
| Property | Type | Description |
|---|---|---|
type | string | Required. Data type of the field. |
label | string | Display label for UI validation messages. |
required | boolean | If true, the field cannot be null/undefined. Default: false. |
unique | boolean | If true, enforces unique values in the database. Default: false. |
defaultValue | any | Default value if not provided during creation. |
index | boolean | Creates a database index for this field. |
searchable | boolean | Enables traditional keyword-based search (e.g., exact match, SQL LIKE). |
sortable | boolean | Hint that this field can be used for sorting in UI. |
description | string | Help text or documentation for the field. |
ai_context | object | Optional. AI-friendly context for this specific field. |
Field-Level AI Context
Each field can include an ai_context block to help AI understand its purpose and usage:
2.2 Supported Field Types
| Type | Description | Specific Properties |
|---|---|---|
| Basic Types | ||
text | Single line text. | min_length, max_length, regex |
textarea | Multiline text. | rows, min_length, max_length |
markdown | Markdown formatted text. | |
html | Rich text content (HTML). | |
number | Numeric value (integer or float). | precision, min, max |
currency | Monetary value. | scale, min, max |
percent | Percentage value (0-1). | scale, min, max |
boolean | true or false. | |
| System/Format Types | ||
email | Email address with validation. | |
phone | Phone number formatting. | |
url | Web URL validation. | |
password | Encrypted or masked string. | |
| Date & Time | ||
date | Date only (YYYY-MM-DD). | |
datetime | Date and time (ISO string). | |
time | Time only (HH:mm:ss). | |
| Complex/Media | ||
file | File attachment (stored as JSON). See Attachment API. | multiple, accept, max_size |
image | Image attachment (stored as JSON). Supports avatars, photos, galleries. See Attachment API. | multiple, accept, max_size, max_width, max_height |
location | Geolocation (lat/lng JSON). | |
| Relationships | ||
select | Selection from a list. | options, multiple |
lookup | Reference to another object. | reference_to, multiple |
master_detail | Strong ownership relationship. | reference_to (Required) |
| Advanced | ||
formula | Read-only calculated field. | expression, data_type |
summary | Roll-up summary of child records. | summary_object, summary_type, summary_field, summary_filters |
auto_number | Auto-incrementing unique identifier. | auto_number_format |
object | JSON object structure. | |
grid | Array of objects/rows. | |
vector | Vector embedding for AI search. | dimension |
2.3 Relationship Fields
Relationship fields (lookup, master_detail) connect objects together. For AI-friendly metadata, consider adding semantic context about the relationship's meaning.
Basic Relationship:
AI-Enhanced Relationship:
Master-Detail Relationship:
| Property | Type | Description |
|---|---|---|
reference_to | string | Required. The name of the target object. |
multiple | boolean | If true, allows multiple selections (one-to-many). Default: false. |
ai_context.intent | string | Business purpose of this relationship. |
ai_context.semantic_type | string | Type: ownership, hierarchy, association, aggregation. |
ai_context.selection_guidance | string | Hints for selecting appropriate related records. |
2.4 Select Options
Options for select can be a simple list or label/value pairs. For AI-friendly metadata, you can add context to each option to explain its meaning and when it should be used.
Simple Options:
AI-Enhanced Options with State Machine:
This state machine information enables:
- Validation: Prevent invalid state transitions
- UI: Show only valid next states in dropdowns
- Automation: Trigger workflows on state changes
- AI Generation: Generate realistic test data following proper state flow
3. Indexes
Indexes improve query performance. You can add AI context to explain the purpose of each index, helping future developers and AI tools understand optimization decisions.
3.1 Field-Level Indexes
You can define simple indexes directly on the field:
3.2 Object-Level Indexes
For composite indexes (spanning multiple fields), define them under the indexes key at the root of the file.
| Property | Type | Description |
|---|---|---|
fields | string[] | Required. List of field names to include in the index. |
unique | boolean | If true, requires values to be unique combination. Default: false. |
ai_context.intent | string | Why this index exists. |
ai_context.common_query | string | Typical query this index optimizes. |
4. AI & Vector Search
ObjectQL supports AI-native features like semantic search and vector embeddings directly in the schema definition.
4.1 AI Configuration
You can enable semantic search and other AI capabilities using the ai property at the root of the file.
| Property | Type | Description |
|---|---|---|
search.enabled | boolean | Enables semantic search. System will automatically manage vector storage. |
search.fields | string[] | List of text fields to concatenate and embed. |
search.model | string | Model ID (e.g. openai/text-embedding-3-small). Defaults to system setting. |
search.target_field | string | Optional. The name of a manual vector field to store embeddings in. |
4.2 Vector Fields
For more granular control, you can define explicit vector fields. This is useful if you want to store embeddings from external sources or multiple embeddings per record.
5. Internationalization (i18n)
ObjectQL is built to support creating global applications. The philosophy is to keep the core schema clean and manage translations separately.
5.1 Metadata Translation (UI)
All user-facing text defined in *.object.yml (Object Labels, Field Labels, Help Text, Select Options) should be translated via external JSON files. This separation allows AI agents to translate the entire UI in one go without touching the schema logic.
Directory Structure:
Translation File Format (project.json):
The structure mirrors the object definition but only contains translatable strings.
5.2 Data Content
ObjectQL does not enforce a specific "multi-language column" format (like JSON fields) in the core spec, as this often complicates indexing and reporting.
Recommended strategies for content translation:
- Separate Record Strategy: Store different language versions as separate records with a
localefield and amaster_id. - Translation Tables: Use a standard relational design (e.g.,
Product->ProductTranslation).
6. Type Generation (CLI)
To achieve strict type safety in your Hooks and Actions, you should use the Code Generation tool.
6.1 Usage
6.2 Using Generated Types
Once generated, you can import the Interfaces directly. This ensures that your code is always in sync with your metadata.
7. Complete AI-Enhanced Example
Here's a complete example showing how to leverage AI context throughout your object definition:
This AI-enhanced metadata enables:
- Better Code Generation: AI tools understand intent and generate correct code
- Intelligent Validation: AI can suggest validation rules based on business rules
- Realistic Test Data: AI generates test data following proper patterns
- Documentation: AI can auto-generate comprehensive documentation
- Query Optimization: AI understands common access patterns for indexing