# Types, sockets and validation

Use primitive and exact custom JSON Schema contracts without assuming automatic coercion or structural compatibility.

Canonical URL: https://opennodeflow.dev/wiki/types/
JSON reference: https://opennodeflow.dev/wiki/types/index.json
Source snapshot: 2026-10-23

Every socket has a programmatic ID, a display name and an expected type. Data sockets can also declare presence, defaults, help text and an exact custom type version. Control sockets select execution paths; they are not JSON data and cannot connect through `any`.

## Primitive contracts

| Type | Accepted value |
| --- | --- |
| `string` | JSON string |
| `number` | Finite JSON number, without string coercion |
| `boolean` | JSON boolean |
| `object` | JSON object; not an array or null |
| `array` | JSON array with unrestricted element shape |
| `any` | JSON-compatible value, including null |
| `control` | Execution route, excluded from data-value validation |

Required describes **presence**, not truthiness. Zero, false and an empty string are present values. An absent optional number is valid; an optional number explicitly set to null is invalid. A required `any` containing null is present. JavaScript `undefined` disappears during JSON transport and becomes missing.

## Connection rules

Identical primitives connect. Identical custom type IDs connect only when their effective pinned versions match. `any` can connect to other data types in either direction, but the receiver still checks the actual runtime value. This is a deliberate dynamic boundary, not a way to disable downstream schemas.

A custom source whose schema has a single top-level type such as `object` can feed the corresponding primitive input. A plain `object` source cannot automatically feed an arbitrary custom type. Different custom type IDs remain incompatible even when their schemas happen to be identical. Nullable top-level unions do not satisfy the simple custom-to-primitive rule.

## Create a useful custom type

Create a Type asset and publish a JSON Schema such as:

```json
{
  "type":"object",
  "properties":{
    "sampleId":{"type":"string","minLength":1},
    "value":{"type":"number","minimum":0}
  },
  "required":["sampleId","value"],
  "additionalProperties":false
}
```

Choose that published type in socket selectors. API authors must use the returned definition ID and chosen version, not the display name. Keep nested reusable schemas local with definitions and local `$ref` paths; ONF does not resolve another library type ID as a global schema reference.

The validator uses Ajv with all errors enabled, strict mode off and **format validation disabled**. A schema `format` such as email or date-time does not establish string correctness. Use an explicit pattern or validation code when needed. No automatic defaults or type coercion are applied during validation.

## Diagnose a mismatch

Inspect the source and target IDs, exact versions, presence and actual value. Validate graph literals before running; connected inputs are checked before their receiving code, and returned outputs are checked after execution. Input validation failure is not repaired by retrying the same body.

Use [codecs](/wiki/codecs/) or [mapping](/wiki/mapping/) for explicit transformations. Read [versioning](/wiki/versioning/) before upgrading one side of a typed connection.

---

## Documentation provenance

- `docs/TYPES-AND-VERSIONING.md`
- `docs/AUTHORING.md`

This page describes maintained source, not a live inventory or an authorization to perform actions.
