# Data Lookup

> Retrieves a value from a provided dictionary or map based on a specific key.

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

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

Retrieves a value from a provided dictionary or map based on a specific key.

This operator is used for simple reference data enrichment. It takes a static or dynamic source map and attempts to find a match for the input key.

**Use Cases:**
- **Enrichment:** looking up a "Country Name" from a "Country Code" (e.g., "US" -> "United States").
- **Mapping:** Translating status codes (e.g., 200 -> "OK").
- **Authorization:** Checking if a User ID exists in an "Admin List".

## Configuration

- `source` (object, required): Key-Value pairs to search within (e.g., {"US": "United States"}).
- `key_template` (string, required, accepts expressions): Key or dotted path looked up in the dictionary (lodash get). Use {{ }} to derive it from the payload, e.g. {{ $json.country_code }}. JSONata is not supported.

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

- `found` (default): Key exists in dictionary.
- `miss`: Key not found.
- `error`: Error

## Input contract

- `payload` (object, optional): Context for key resolution.

## Output contract

- `value` (any, optional): The retrieved value from the dictionary.
- `found` (boolean, optional)

## In expressions

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

- `$("Data Lookup").item.json.value` (any): The retrieved value from the dictionary. **The worker does not return it: reads as undefined.**
- `$("Data Lookup").item.json.found` (boolean) **The worker does not return it: reads as undefined.**
- `$("Data Lookup").item.json.country_code` (string) = `"US"` (Not suggested by the editor)
- `$("Data Lookup").item.json.lookup_result` (string) = `"United States"` (Not suggested by the editor)


## How it works

Looks up a key or dotted path in a dictionary with lodash `get` and routes to `found` with the value added as `lookup_result`, or to `miss` with the payload unchanged.

1. Resolves the config: `{{ }}` in `source` and `key_template` are evaluated by the Expression Engine.
2. Fails when `key_template` is missing or resolves to an empty value.
3. Converts the key to a string and reads it with `_.get(source, key)`: dotted paths and indexes such as `regions.north[0]` work. JSONata is not used.
4. Any value other than `undefined` (including `null`) counts as found: returns the payload plus `lookup_result` through `found`.
5. Otherwise returns the payload unchanged through `miss`. Both set `meta` `{ found, key }`.

## In a workflow

### Node

```json
{
  "node_id": "node-country-name",
  "label": "Country name",
  "operator_slug": "data.lookup",
  "operator_version": "1.0.0",
  "config": {
    "source": {
      "US": "United States",
      "CO": "Colombia",
      "MX": "Mexico"
    },
    "key_template": "{{ $json.country_code }}"
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "country_code": "US",
    "lookup_result": "United States"
  },
  "meta": {
    "found": true,
    "key": "US"
  },
  "port": "found"
}
```

## Output ports (behaviour in the code)

### `found`

The key exists in `source`.

```json
{
  "country_code": "US",
  "lookup_result": "United States"
}
```

### `miss`

The key does not exist in `source`.

```json
{
  "country_code": "BR"
}
```

### `error`

`key_template` is empty.

```json
{
  "ok": false,
  "errors": [
    "Key template is required"
  ],
  "port": "error"
}
```

## Behaviour in the code

- `key_template`: Text without `{{ }}` is taken as a literal key. To read the key from the payload write `{{ $json.country_code }}`.
- `source`: Defaults to `{}` when missing, so every lookup misses. It can be a `{{ }}` that returns an object from an earlier node.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `Key template is required` | `error` | `key_template` is missing, or its `{{ }}` resolved to `undefined`, `null`, `""`, `0` or `false`. |

## Notes and limits

- The output key is `lookup_result`; the `value` and `found` fields of the output contract are not produced (`found` exists only in `meta`).
- `meta` is recorded in the run steps only: downstream nodes receive `data` as their payload and cannot read `meta` through `$json` or `$("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.lookup",
  "name": "Data Lookup",
  "category": "data",
  "version": "1.0.0",
  "description": "Retrieves a value from a provided dictionary or map based on a specific key.\n\n  This operator is used for simple reference data enrichment. It takes a static or dynamic source map and attempts to find a match for the input key.\n\n  **Use Cases:**\n  - **Enrichment:** looking up a \"Country Name\" from a \"Country Code\" (e.g., \"US\" -> \"United States\").\n  - **Mapping:** Translating status codes (e.g., 200 -> \"OK\").\n  - **Authorization:** Checking if a User ID exists in an \"Admin List\".",
  "capabilities": [
    "enrichment",
    "map",
    "dictionary"
  ],
  "config_schema": {
    "type": "object",
    "required": [
      "source",
      "key_template"
    ],
    "properties": {
      "source": {
        "type": "object",
        "title": "Dictionary / Map",
        "description": "Key-Value pairs to search within (e.g., {\"US\": \"United States\"})."
      },
      "key_template": {
        "type": "string",
        "title": "Key Expression",
        "format": "expression",
        "description": "Key or dotted path looked up in the dictionary (lodash get). Use {{ }} to derive it from the payload, e.g. {{ $json.country_code }}. JSONata is not supported."
      },
      "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": {
      "payload": {
        "type": "object",
        "description": "Context for key resolution."
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "description": "The found value or original payload.",
    "properties": {
      "value": {
        "type": "any",
        "description": "The retrieved value from the dictionary."
      },
      "found": {
        "type": "boolean"
      }
    }
  },
  "ports": [
    {
      "port_id": "found",
      "label": "Found",
      "is_default": true,
      "description": "Key exists in dictionary."
    },
    {
      "port_id": "miss",
      "label": "Missing",
      "description": "Key not found."
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "sync",
  "tags": [
    "map",
    "dictionary",
    "lookup"
  ],
  "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",
  "required": [
    "source",
    "key_template"
  ],
  "properties": {
    "source": {
      "type": "object",
      "title": "Dictionary / Map",
      "description": "Key-Value pairs to search within (e.g., {\"US\": \"United States\"})."
    },
    "key_template": {
      "type": "string",
      "title": "Key Expression",
      "format": "expression",
      "description": "Key or dotted path looked up in the dictionary (lodash get). Use {{ }} to derive it from the payload, e.g. {{ $json.country_code }}. JSONata is not supported."
    },
    "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": {
    "payload": {
      "type": "object",
      "description": "Context for key resolution."
    }
  }
}
```

### output_contract_schema

```json
{
  "type": "object",
  "description": "The found value or original payload.",
  "properties": {
    "value": {
      "type": "any",
      "description": "The retrieved value from the dictionary."
    },
    "found": {
      "type": "boolean"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "found",
    "label": "Found",
    "is_default": true,
    "description": "Key exists in dictionary."
  },
  {
    "port_id": "miss",
    "label": "Missing",
    "description": "Key not found."
  },
  {
    "port_id": "error",
    "label": "Error"
  }
]
```
