# Modify Experiment Settings

In the Settings Details Page, click 'More Actions' -> 'Edit Settings'

![Modify Settings Edit Button](https://2689420226-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFMRO0BquZrbmgj6RBGJL%2Fuploads%2FdkNL9uqQbsiQe4DKDp5Q%2F03_edit_settings_button.png?alt=media\&token=c04a4b36-e925-496f-aece-d7f49cf8389f)

In the Edit Experiment Page, you can edit the `randomization_key`, the list of `segmenters` and their variable mappings.

![Modify Settings Edit Page](https://2689420226-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFMRO0BquZrbmgj6RBGJL%2Fuploads%2Fgit-blob-668866c9dfd3d11b236636c6d10877badb80f890%2F03_edit_settings_form.png?alt=media)

When modifying settings, please take note of the following pointers:

1. Segmenters with asterisk(\*) are required segmenters that cannot be removed from the selected list.
2. Removing Segmenters will not be allowed when there are 1 or more 'active' and 'yet-to-end' experiments that are not defined granularly enough.

   The following scenario is an example:

   * Currently selected segmenters: `country`, `service`
   * Currently created experiments:

   ```
       // Experiment 1
       {
           "name": "test-exp-1",
           "created_at": "2022-06-27T10:00:00.0000Z",
           "segment": {
               "country": ["SG"],
               "service": [1]
           },
           ...
       }

       // Experiment 2
       {
           "name": "test-exp-2",
           "created_at": "2022-06-27T10:00:00.0000Z",
           "segment": {
               "country": ["SG"],
               "service": [2]
           },
           ...
       }
   ```

   Suppose we want to remove `service` segmenter from the project, this would make it impossible to distinguish between both experiments when XP tries to fetch a treatment because the only segmenter is `country` and both experiments have the same value, i.e, `SG` in this case.

## Edit Validation

Validation configuration can be edited and configuration can be tested in the playground provided in the Edit Validation View. Both External Validation URL and Treatment Validation Rules can be left blank.

From the Validation Detail page, click 'More Actions' -> 'Configure Validation'.

![Edit Validation Button](https://2689420226-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFMRO0BquZrbmgj6RBGJL%2Fuploads%2FbIvJJymQnNSAclcTlnDG%2F03_edit_settings_validation_button.png?alt=media\&token=27bbc6cd-20d4-4df9-838d-46b62570b3e5)

### Edit Validation Page

1. In the Edit Validation Page, you can edit the Validation's configuration. ![Edit Validation](https://2689420226-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFMRO0BquZrbmgj6RBGJL%2Fuploads%2FSLqXA52055jVg7q1F0gB%2F03_edit_settings_validation.png?alt=media\&token=ab77da6c-bc00-4277-8e1d-f3f1331ac7f3)
2. External Validation: URL of external validation to validate experiments.

   * Note that the external validation endpoint will be called whenever experiments or treatments are created or edited. XP will send a POST request to the following HTTP endpoint with the following payload that has to be handled by the custom web service:

   ```
   POST /validate-experiment
   {
       "entity_type": // oneOf {experiment, treatment}
       "operation": // oneOf {create, update}
       "data": {

       } // The json object representing the new experiment or treatment being created or saved
       "context": {
           "current_data": {} // Current entity, in update operations
       } // Optional context information
   }
   ```

   * A response with status code of 200 will be deemed as successful. A timeout of 5 seconds is also configured to treat any hanging call to the validation URL as a failure.
3. Treatment Validation Rules: Rules, specified in the form of [Go Templates](https://pkg.go.dev/text/template), used to validate treatment configuration of experiments. In addition to the default Go Template operations, those from the [Sprig library](http://masterminds.github.io/sprig/) are also supported. All rules will be evaluated on the treatment configuration and must return `true` for the operation to be permitted. Some examples below.

To test that the data satisfies one of the following conditions:

* `.field1`=`"abc"` and `.field2`=`"def"` and `.field3.field4` is of type `float`
* (OR) `.field1`=`"xyz"` and `.field2`=`"def"` and `.field3.field4` is of type `int`

```
{{- or (and
         (eq .field1 "abc")
         (eq .field2 "def")
         (contains "float" (typeOf .field3.field4)))
     (and
         (eq .field1 "xyz")
         (eq .field2 "def")
         (contains "int" (typeOf .field3.field4))) -}}
```

To test that a certain property `weight` in an array field `.config_details.models` sums to 1 across all elements:

```
{{- $sum := 0 -}}
 {{- range $index, $item := .config_details.models -}}
   {{- $sum = (addf $sum $item.weight) -}}
 {{- end -}}
{{- eq $sum 1.0 -}}
```

### Creating or Updating an Experiment

Sample experiment schema:

```json
{
    "id":0,
    "project_id":1,
    "name":"test-experiment-create",
    "description":"Test description",
    "type":"Switchback",
    "interval":60,
    "tier":"default",
    "treatments":[
        {
            "configuration":{
                "meta":{
                    "created-by":"test"
                },
                "weight":0.2
            }, 
            "name":"treatment",
            "traffic":100
        }
    ],
    "segment":{
        "country":[
            "ID",
            "SG"
        ]
    }
}
```

* The entire experiment will be sent to the validation url for validation
* *Each* treatment configuration within the experiment will be validated with *all* of the treatment validation rules

Both of these conditions must be fulfilled before the experiment can be created or updated successfully.

### Creating or Updating a Treatment

Sample treatment schema:

```json
{
    "field1":"abc", 
    "field2":"def", 
    "field3":{
        "field4":0.1
    }
}
```

* The treatment configuration will be sent to the validation url for validation
* The treatment configuration will be validated with *all* of the treatment validation rules

Both of these conditions must be fulfilled before the treatment can be created or updated successfully.

## Validation Playground

To test entities such as treatment configuration, before saving them, you can access the validation playground page by clicking the blue button `Playground` at the top right hand corner of the `Edit Validation Page`.

![Validation Playground Button](https://2689420226-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFMRO0BquZrbmgj6RBGJL%2Fuploads%2FmqkTkPkS7wRYZmj30Tip%2F03_validation_playground_button.png?alt=media\&token=9b040270-ba6a-4517-8266-a5ee0db2e2fb)

1. External Validation: Select the `External Validation` radio button under `Validation Type` and fill in the `Sample Data` text field with a sample **payload** that you would like to send your validation url.
2. Treatment Validation Rules: Select the `Treatment Validation Rules` radio button under `Validation Type` and fill in the `Sample Data` text field with a **treatment configuration** that you would like to validate against the treatment validation rules.

Click on validate once you are done to perform the validation.

![Validation Playground Confirmation](https://2689420226-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFMRO0BquZrbmgj6RBGJL%2Fuploads%2FScGfH3bf7gpCvpYD5DnZ%2F03_validation_playground_confirmation.png?alt=media\&token=f1585944-ce92-4133-a4bb-a2ace5d052ad)
