Response structure

Understand the common shape of view responses.
View as Markdown

View responses are returned as JSON.

Most view responses use a shared structure: a top-level data array, one object for each generated view, and view-specific data under view_data.

Top-level response

A view response contains a data array.

When you generate one view, the array contains one item. When you generate multiple views in the same request, the array contains one item per generated view.

1{
2 "data": [
3 {
4 "views_version": {
5 "major": 1,
6 "minor": 0,
7 "patch": 0
8 },
9 "output_version": {
10 "major": 1,
11 "minor": 0,
12 "patch": 0
13 },
14 "view_type": "HISTOGRAM",
15 "view_data": {
16 "columns": ["field", "value", "count"],
17 "index": [0, 1, 2],
18 "data": [
19 ["gender", "Female", 42],
20 ["gender", "Male", 38],
21 ["gender", "Unknown", 3]
22 ],
23 "foreign_keys": [],
24 "labels": {},
25 "types": [
26 { "data_type": "string" },
27 { "data_type": "string" },
28 { "data_type": "integer" }
29 ]
30 }
31 }
32 ]
33}

View metadata

Each view object includes metadata that identifies the view output.

FieldDescription
views_versionVersion of the view generation logic.
output_versionVersion of the response format.
view_typeType of view returned in this item.
view_dataView-specific output data.

Some deployed model views may include additional version fields, such as commons_version or core_version.

Dataframe structure

Most view_data objects are returned as split-orientation dataframes.

FieldDescription
columnsColumn names for the dataframe.
indexRow index values.
dataValues aligned to the columns and index.
foreign_keysForeign key references included with the dataframe.
labelsOptional labels associated with the dataframe.
typesOptional data type information for each column.

This structure makes view output easier to render as tables, charts, or downstream analysis data.

Nested dataframe views

Some views return more than one dataframe inside view_data.

For example, the Results view returns separate dataframes for model information, query input, predicted output, feature attribution, module attribution, partition data, and decomposition data.

1{
2 "data": [
3 {
4 "view_type": "RESULTS",
5 "view_data": {
6 "model_info": { "columns": [], "index": [], "data": [], "foreign_keys": [] },
7 "query_input": { "columns": [], "index": [], "data": [], "foreign_keys": [] },
8 "predicted_output": { "columns": [], "index": [], "data": [], "foreign_keys": [] },
9 "feature_attribution": { "columns": [], "index": [], "data": [], "foreign_keys": [] },
10 "module_attribution": { "columns": [], "index": [], "data": [], "foreign_keys": [] }
11 }
12 }
13 ]
14}

When a view returns nested dataframes, each nested object follows the same split-orientation pattern.

Working with responses

Use view_type to identify which view was returned, then read view_data according to the page for that view.

For simple views, view_data is usually a single dataframe. For richer explanation views, view_data may contain multiple named dataframes that should be read together.