> For the complete documentation index, see [llms.txt](https://docs.internetobject.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.internetobject.org/collections/collection-rules.md).

# Collection Rules

## Records without a schema

If no schema is defined, each record may have a different shape, and values are mapped to positional indices (`0`, `1`, `2`, …):

```ruby
---
~ John Doe, 20, female
~ true, false
~ marketing, 123, { Z Street, Los Angeles, CA }
```

The first record loads as `{ "0": "John Doe", "1": 20, "2": "female" }`, and so on.

> It is good practice to define a schema even though collections allow schema-less records.

## Empty records

A record consisting of just `~` is an **empty object** (`{}`). It is valid only if **every** field in the schema is optional and/or nullable:

```ruby
~ $schema: { name?*: string, age?*: { int, max: 25 } }
---
~ John, 25     # ✓
~ William      # ✓ (age omitted)
~              # ✓ (empty object; all fields optional/nullable)
```

If any field is required, an empty record fails:

```ruby
~ $schema: { name: string, age?*: { int, max: 25 } }
---
~ John, 25     # ✓
~              # ✗ value-required — name is required
```

## Independent validation & error handling

Each record is validated independently. A failing record is marked as an error; the rest are unaffected:

```ruby
~ $schema: { name: string, age: { int, max: 25 } }
---
~ James, 20    # ✓
~ Alex, 30     # ✗ invalid-range — age exceeds 25
~ Bob, 22      # ✓
```

A conformant processor SHOULD collect per-record errors and continue, rather than stopping at the first failure.

## See Also

* [Collection](/collections/collection.md) · [Creating Collections](/collections/creating-collection.md)
* [Parser Behavior & Recovery](/parsing-and-errors/parser-behavior.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.internetobject.org/collections/collection-rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
