ModelWorks logoModelWorks
JSON TransformObject

defaults

Fill missing keys from a defaults object

defaults

Inserts each key from defaults into the current object only if the key is not already present. Existing values are never overwritten.

Options

OptionTypeRequiredDefaultDescription
defaultsobjectYesObject whose keys provide fallback values.

Example

Input

JSON
{ "model": "gpt-4o-mini", "temperature": 0.7 }

Operation

JSON
{
  "type": "defaults",
  "options": {
    "defaults": {
      "model": "gpt-4-turbo",
      "temperature": 0.2,
      "max_tokens": 1024
    }
  }
}

Output

JSON
{ "model": "gpt-4o-mini", "temperature": 0.7, "max_tokens": 1024 }

In a Circuit Step

JSON
{
  "name": "fill_config_defaults",
  "description": "Backfill any missing config fields with sensible defaults",
  "function": "circuit.core.transform.json",
  "input": {
    "source": "${{ input.config }}",
    "operations": [
      {
        "type": "defaults",
        "options": {
          "defaults": {
            "model": "gpt-4-turbo",
            "temperature": 0.2,
            "max_tokens": 1024
          }
        }
      }
    ]
  },
  "outputs": [
    {
      "name": "config_with_defaults",
      "description": "Config object with defaults applied to missing fields",
      "value": "${{ fill_config_defaults.output.transformed_result }}"
    }
  ]
}

Notes & gotchas

  • Errors with defaults: expected object if the input is not an object.
  • Keys present in the input retain their original value, even if that value is null or an empty string. The check is "key exists", not "value is truthy".
  • For deep defaulting (filling nested keys without overwriting existing ones), pre-merge with merge where the default object is on the left of the chain — i.e., set source to the defaults and merge the input on top, then keep the result.
  • defaults values are used as-is (not selector-evaluated). If you need selector resolution in default values, apply a merge operation with the selectors resolved upstream.
On this page

On this page