> For the complete documentation index, see [llms.txt](https://docs.tonic.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tonic.ai/app/api/quick-start-guide/tonic-api-generator-assignment/generator-api-reference/generator-api-ref-conditional.md).

# Conditional (ConditionalGenerator)

The [Conditional](/app/generation/generators/generator-reference/conditional.md) generator applies different generators to the value conditionally based on any value in the table.

## Link object structure <a href="#generator-api-conditional-link-object" id="generator-api-conditional-link-object"></a>

You do not configure consistency or differential privacy for the Conditional generator.

The `metadata` object is populated from the [`ConditionalMetadata`](https://app.tonic.ai/apidocs/index.html#/models/ConditionalMetadata) object.

The `defaultGenerator` object specifies the generator to apply if none of the conditions are met. It includes a `condition` object with an empty list of conditions.

The `conditionalGenerators` object contains the generators to apply based on one or more conditions. For each entry in `conditionalGenerators`, you identify and configure the generator, and provide the conditions to meet in order to apply that generator. The conditions can be joined by `AND` or `OR`.

Each condition identifies the column for which to check the value, the type of check, the value to check, and the type of data in the column that is checked. To check the value of the current column, set the column to `field_self`.

```json
{
  "schema": "string",
  "table": "string",
  "column": "string",
  "path": "string",  //JSON fields only
  "dataType": "string",  //MongoDB, Amazon DynamoDB, and JSON fields only
  "metadata": {
    "generatorId": "ConditionalGenerator",
    "presetId": "ConditionalGenerator",
    "customValueProcessor": "string", //If custom value processor applied
    "defaultGenerator": {
      "metadata": {
        "presetId": "string",
        "generatorId": "string",
        //Metadata for the selected generator
      },
      "condition": {
          "op": "AND",
          "conditions": []
    },
    "conditionalGenerators": [
      {
        "metadata": {
          "presetId": "string",
          "generatorId": "string",
          "customValueProcessor": "string", //If custom value processor applied
          //Metadata for the selected generator
        },
        "condition": {
          "op": "enum",
          "conditions": [
            {
              "col": "string",
              "op": "enum",
              "val": "string",
              "colDataType": "string"
            }
          ]
        }
      }
    ]
  }
}
```

## Example replacement <a href="#generator-api-conditional-replacement" id="generator-api-conditional-replacement"></a>

In the following example replacement for the Conditional generator, the default generator is the Address generator, which is configured with the zip code as the address type.

The column being configured is `column1`.

If `column1` contains the value `VALUE` and `column2` is not NULL, then the Random Integer generator is applied to `column1`. It applies a value between 0 and 10.

If `column4` contains a value that matches the regular expression `.*`, then the Categorical generator is applied to `column1`. `epsilon` is 1, and differential privacy is disabled.

```json
{
  "name": "column1",
  "table": "consistency",
  "schema": "public",
  "links": [
    {
      "column": "column1",
      "schema": "public",
      "table": "consistency",
      "metadata": {
        "generatorId": "ConditionalGenerator",
        "presetId": "ConditionalGenerator",
        "defaultGenerator": {
          "metadata": {
            "presetId": "AddressGenerator",
            "generatorId": "AddressGenerator",
            "addressType": "ZipCode",
            "isConsistent": false
          }
        },
        "conditionalGenerators": [
          {
            "metadata": {
              "presetId": "RandomIntegerGenerator",
              "generatorId": "RandomIntegerGenerator",
              "min": 0,
              "max": 10
            },
            "condition": {
              "op": "AND",
              "conditions": [
                {
                  "col": "field_self",
                  "op": "contains",
                  "val": "VALUE",
                  "colDataType": "integer"
                },
                {
                  "col": "column2",
                  "op": "is not NULL",
                  "colDataType": "integer"
                }
              ]
            }
          },
          {
            "metadata": {
              "presetId": "CategoricalGenerator",
              "generatorId": "CategoricalGenerator",
              "epsilon": 1,
              "isDifferentiallyPrivate": false
            },
            "condition": {
              "op": "AND",
              "conditions": [
                {
                  "col": "column4",
                  "op": "regex",
                  "val": ".*",
                  "colDataType": "character varying"
                }
              ]
            }
          }
        ]
      }
    }
  ]
}
```


---

# 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.tonic.ai/app/api/quick-start-guide/tonic-api-generator-assignment/generator-api-reference/generator-api-ref-conditional.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.
