

# Endpoint requests for tabular data
<a name="clarify-processing-job-data-format-tabular-request"></a>

To obtain model predictions for post-training bias analysis and feature importance analysis, SageMaker Clarify processing jobs serialize the tabular data into bytes and sends these to an inference endpoint as a request payload. This tabular data is either sourced from the input dataset, or it's generated. If it's synthetic data, it's generated by the explainer for SHAP analysis or PDP analysis.

The data format of the request payload should be specified by the analysis configuration `content_type` parameter. If the parameter is not provided, the SageMaker Clarify processing job will use the value of the `dataset_type` parameter as the content type. For more information about `content_type` or `dataset_type`, see [Analysis Configuration Files](clarify-processing-job-configure-analysis.md).

The following sections show example endpoint requests in CSV and JSON Lines formats.

## Endpoint request in CSV format
<a name="clarify-processing-job-data-format-tabular-request-csv"></a>

The SageMaker Clarify processing job can serialize data to CSV format (MIME type: `text/csv`). The following table shows examples of the serialized request payloads.


| Endpoint request payload (string representation) | Comments | 
| --- | --- | 
|  '1,2,3,4'  |  Single record (four numerical features).  | 
|  '1,2,3,4\$1n5,6,7,8'  |  Two records, separated by line break '\$1n'.  | 
|  '"This is a good product",5'  |  Single record (a text feature and a numerical feature).  | 
|  ‘"This is a good product",5\$1n"Bad shopping experience",1’  |  Two records.  | 

## Endpoint request is in JSON Lines format
<a name="clarify-processing-job-data-format-tabular-request-jsonlines"></a>

The SageMaker Clarify processing job can serialize data to SageMaker AI JSON Lines dense format (MIME type: `application/jsonlines`). For more information about JSON Lines, see [JSONLINES request format](cdf-inference.md#cm-jsonlines).

To transform tabular data into JSON data, provide a template string to the analysis configuration `content_template` parameter. For more information about `content_template` see [Analysis Configuration Files](clarify-processing-job-configure-analysis.md). The following table shows examples of serialized JSON Lines request payloads.


| Endpoint request payload (string representation) | Comments | 
| --- | --- | 
|  '\$1"data":\$1"features":[1,2,3,4]\$1\$1'  |  Single record. In this case, the template looks like `'{"data":{"features":$features}}' `and `$features` is replaced by the list of features `[1,2,3,4]`.  | 
|  '\$1"data":\$1"features":[1,2,3,4]\$1\$1\$1n\$1"data":\$1"features":[5,6,7,8]\$1\$1'  |  Two records.  | 
|  '\$1"features":["This is a good product",5]\$1'  |  Single record. In this case, the template looks like `'{"features":$features}'` and \$1features is replaced by the list of features `["This is a good product",5]`.  | 
|  '\$1"features":["This is a good product",5]\$1\$1n\$1"features":["Bad shopping experience",1]\$1'  |  Two records.  | 

## Endpoint request is in JSON format
<a name="clarify-processing-job-data-format-tabular-request-json"></a>

A SageMaker Clarify processing job can serialize data to arbitrary JSON structures (MIME type: `application/json`). To do this, you must provide a template string to the analysis configuration `content_template` parameter. This is used by the SageMaker Clarify processing job to construct the outer JSON structure. You must also provide a template string for `record_template`, which is used to construct the JSON structure for each record. For more information about `content_template` and `record_template`, see [Analysis Configuration Files](clarify-processing-job-configure-analysis.md). 

**Note**  
Because `content_template` and `record_template` are string parameters, any double quote characters (`"`) that are part of the JSON serialized structure should be noted as an escaped character in your configuration. For example, if you want to escape a double quote in Python, you could enter the following for `content_template`.  

```
"{\"data\":{\"features\":$record}}}"
```

The following table shows examples of serialized JSON request payloads and the corresponding `content_template` and `record_template` parameters that are required to construct them.


| Endpoint request payload (string representation) | Comments | content\$1template | record\$1template | 
| --- | --- | --- | --- | 
|  '\$1"data":\$1"features":[1,2,3,4]\$1\$1'  |  Single record at a time.  |  '\$1"data":\$1"features":\$1record\$1\$1\$1'  |  “\$1features”  | 
|  '\$1"instances":[[0, 1], [3, 4]], "feature-names": ["A", "B"]\$1'  |  Multi-records with feature names.  |  ‘\$1"instances":\$1records, "feature-names":\$1feature\$1names\$1'  |  “\$1features"  | 
|  '[\$1"A": 0, "B": 1\$1, \$1"A": 3, "B": 4\$1]'  |  Multi-records and key-value pairs.  |  “\$1records"  |  “\$1features\$1kvp"  | 
|  ‘\$1"A": 0, "B": 1\$1'  |  Single record at a time and key-value pairs.  |  "\$1record"  |  "\$1features\$1kvp"  | 
|  ‘\$1"A": 0, "nested": \$1"B": 1\$1\$1'  |  Alternatively, use the fully verbose record\$1template for arbitrary structures.  |  "\$1record"  |  '\$1"A": "\$1\$1A\$1", "nested": \$1"B": "\$1\$1B\$1"\$1\$1'  | 