# Generate UUID

> Generates a cryptographically strong unique identifier (UUID/NanoID).

Source: https://docs.sommatic.ai/en/nodes/data.uuid/

- Slug: `data.uuid`
- Family: Data
- Version: 1.0.0
- Status: Available
- Execution: sync

Generates a cryptographically strong unique identifier (UUID/NanoID).

This operator produces unique strings suitable for database keys, transaction IDs, or idempotency tokens.

**Formats:**
- **v4:** Random UUID (Standard).
- **v5:** Name-based UUID (Deterministic based on namespace + name).
- **NanoID:** Compact, URL-friendly unique string.

**Use Cases:**
- Assigning an ID to a newly created resource.
- Generating a correlation ID for tracking request chains.

## Configuration

- `version` (string, optional): Type of ID to generate. Default: `v4`. Allowed values: `v4`, `v5`, `nanoid`.
- `namespace_id` (string, optional): Namespace UUID for deterministic v5 generation.
- `name` (string, optional): Input name used for deterministic v5 generation.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `out` (default): Generated
- `error`: Error

## Input contract

- `name` (string, optional): Input name for v5 generation (optional).

## Output contract

- `uuid` (string, optional): The generated unique identifier.

## In expressions

What a later node can read from this node's output with `$("Generate UUID").item.json.<path>` (write your node's label instead of `Generate UUID`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Generate UUID").item.json.uuid` (string) = `"3b1f8e2a-6c4d-4f7e-9a2b-8d5c1e0f7a34"`: The generated unique identifier.
- `$("Generate UUID").item.json.result` (string) = `"3b1f8e2a-6c4d-4f7e-9a2b-8d5c1e0f7a34"` (Not suggested by the editor)


## How it works

Generates a random v4 UUID, a deterministic v5 UUID or a 20-character random hex id, returned as `{ uuid, result }`.

1. Resolves the config; `version` defaults to `v4`.
2. `v4`: random UUID.
3. `v5`: requires `namespace_id` (a UUID) and `name`; the same pair always gives the same UUID.
4. `nanoid`: 10 random bytes as hex (20 characters); it is not a real nanoid.
5. Returns `{ uuid, result }` (same value twice) through `out`; the incoming payload is not passed through.

## In a workflow

### Node

```json
{
  "node_id": "node-order-key",
  "label": "Order key",
  "operator_slug": "data.uuid",
  "operator_version": "1.0.0",
  "config": {
    "version": "v5",
    "namespace_id": "6ba7b811-9dad-11d1-80b4-00c04fd430c8",
    "name": "{{ $json.order_id }}"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "uuid": "3b1f8e2a-6c4d-5f7e-9a2b-8d5c1e0f7a34",
    "result": "3b1f8e2a-6c4d-5f7e-9a2b-8d5c1e0f7a34"
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

The id was generated.

```json
{
  "uuid": "3b1f8e2a-6c4d-4f7e-9a2b-8d5c1e0f7a34",
  "result": "3b1f8e2a-6c4d-4f7e-9a2b-8d5c1e0f7a34"
}
```

### `error`

v5 inputs are missing or invalid, or `version` is unknown.

```json
{
  "ok": false,
  "errors": [
    "UUID Error: v5 requires namespace_id and name"
  ],
  "port": "error"
}
```

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `UUID Error: v5 requires namespace_id and name` | `error` | `version` is `v5` and one of the two keys is empty. |
| `UUID Error: Invalid UUID` | `error` | `namespace_id` is not a valid UUID. |
| `UUID Error: Unknown UUID version: <version>` | `error` | `version` is not `v4`, `v5` or `nanoid`. |

## Notes and limits

- The payload is replaced by `{ uuid, result }`: reference earlier data with `$("Node")`, or generate the id inline with `{{ $uuid }}` in another node.
- When the envelope has no `data` (or `data` is falsy), the engine stores the whole envelope as the node output: on `error` the next node receives `{ ok: false, errors: [...], port: "error" }` as its payload.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "data.uuid",
  "name": "Generate UUID",
  "category": "data",
  "version": "1.0.0",
  "description": "Generates a cryptographically strong unique identifier (UUID/NanoID).\n\n  This operator produces unique strings suitable for database keys, transaction IDs, or idempotency tokens.\n\n  **Formats:**\n  - **v4:** Random UUID (Standard).\n  - **v5:** Name-based UUID (Deterministic based on namespace + name).\n  - **NanoID:** Compact, URL-friendly unique string.\n\n  **Use Cases:**\n  - Assigning an ID to a newly created resource.\n  - Generating a correlation ID for tracking request chains.",
  "capabilities": [
    "utils",
    "id-generation",
    "security"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "version": {
        "type": "string",
        "enum": [
          "v4",
          "v5",
          "nanoid"
        ],
        "default": "v4",
        "title": "Format",
        "description": "Type of ID to generate."
      },
      "namespace_id": {
        "type": "string",
        "title": "Namespace UUID (v5 only)",
        "description": "Namespace UUID for deterministic v5 generation."
      },
      "name": {
        "type": "string",
        "title": "Name (v5 only)",
        "description": "Input name used for deterministic v5 generation."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "name": {
        "type": "string",
        "description": "Input name for v5 generation (optional)."
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "uuid": {
        "type": "string",
        "description": "The generated unique identifier."
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Generated",
      "is_default": true
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "id",
    "uuid",
    "key",
    "generator"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "version": {
      "type": "string",
      "enum": [
        "v4",
        "v5",
        "nanoid"
      ],
      "default": "v4",
      "title": "Format",
      "description": "Type of ID to generate."
    },
    "namespace_id": {
      "type": "string",
      "title": "Namespace UUID (v5 only)",
      "description": "Namespace UUID for deterministic v5 generation."
    },
    "name": {
      "type": "string",
      "title": "Name (v5 only)",
      "description": "Input name used for deterministic v5 generation."
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  }
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "description": "Input name for v5 generation (optional)."
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "uuid": {
      "type": "string",
      "description": "The generated unique identifier."
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Generated",
    "is_default": true
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
