> 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

Validation rules for collections — schema-less records, empty records, errors.

## 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     # ✓
~              # ✗ missing-value — 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     # ✗ mismatched-max — 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
