{
  "schema_version": "1.0",
  "nodes": [
    {
      "id": "price_list",
      "type": "input/data",
      "label": "Price list (Excel)",
      "parameters": {
        "dataConfig": {
          "assetPath": "__PRICE_LIST_ASSET_PATH__",
          "format": "auto",
          "headerRow": 1,
          "locale": "it-IT",
          "formulaPolicy": "cached_value",
          "emptyBehavior": "fail",
          "maxRows": 200
        }
      }
    },
    {
      "id": "winery",
      "type": "input/json_value",
      "label": "Winery and catalog",
      "parameters": {
        "required": true
      }
    },
    {
      "id": "wines",
      "type": "enumerate/data_rows",
      "label": "One wine at a time",
      "parameters": {
        "rowMapping": {
          "columns": [
            {
              "sourceColumn": "Codice",
              "outputPort": "code",
              "outputType": "text",
              "selected": true,
              "label": "Codice",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Vino",
              "outputPort": "name",
              "outputType": "text",
              "selected": true,
              "label": "Vino",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Denominazione",
              "outputPort": "denomination",
              "outputType": "text",
              "selected": true,
              "label": "Denominazione",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Tipologia",
              "outputPort": "type",
              "outputType": "text",
              "selected": true,
              "label": "Tipologia",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Annata",
              "outputPort": "vintage",
              "outputType": "number",
              "selected": true,
              "label": "Annata",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Uvaggio",
              "outputPort": "grapes",
              "outputType": "text",
              "selected": true,
              "label": "Uvaggio",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Gradazione",
              "outputPort": "alcohol",
              "outputType": "number",
              "selected": true,
              "label": "Gradazione",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Formato (cl)",
              "outputPort": "size",
              "outputType": "number",
              "selected": true,
              "label": "Formato (cl)",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Prezzo ristorazione",
              "outputPort": "price",
              "outputType": "number",
              "selected": true,
              "label": "Prezzo ristorazione",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Bottiglie disponibili",
              "outputPort": "stock",
              "outputType": "number",
              "selected": true,
              "label": "Bottiglie disponibili",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Note dell'enologo",
              "outputPort": "notes",
              "outputType": "text",
              "selected": true,
              "label": "Note dell'enologo",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Abbinamenti",
              "outputPort": "pairing",
              "outputType": "text",
              "selected": true,
              "label": "Abbinamenti",
              "conversion": "strict"
            },
            {
              "sourceColumn": "Foto",
              "outputPort": "photo",
              "outputType": "text",
              "selected": true,
              "label": "Foto",
              "conversion": "strict"
            }
          ],
          "emptyBehavior": "fail",
          "onConversionError": "fail",
          "startRow": 0,
          "maxRows": 40
        }
      }
    },
    {
      "id": "facts",
      "type": "text/template",
      "label": "Facts of the wine",
      "parameters": {
        "template": "Vino: [name]\nDenominazione: [denomination]\nTipologia: [type]\nUvaggio: [grapes]\nNote dell'enologo: [notes]\nAbbinamenti: [pairing]",
        "placeholders": [
          {
            "name": "name",
            "inputPort": "name"
          },
          {
            "name": "denomination",
            "inputPort": "denomination"
          },
          {
            "name": "type",
            "inputPort": "type"
          },
          {
            "name": "grapes",
            "inputPort": "grapes"
          },
          {
            "name": "notes",
            "inputPort": "notes"
          },
          {
            "name": "pairing",
            "inputPort": "pairing"
          }
        ]
      }
    },
    {
      "id": "writer",
      "type": "ai/text_generation",
      "label": "Write the description",
      "parameters": {
        "system_prompt": "You write the entries of a winery's price list for restaurants and wine bars.\nFrom the facts of one wine, write its description in Italian, for a sommelier or a restaurant owner who is choosing what to list.\n\nRules:\n- Use only the winemaker's notes and the facts given: never invent awards, scores, vineyards, ageing, prices or numbers.\n- Never repeat the name, the denomination, the vintage, the grapes, the alcohol or the price: the catalog prints them.\n- Concrete and warm, no superlatives, no exclamation marks.\n- At most 150 characters (count them): it is printed in a small card.\n\nReturn one JSON object and nothing else: { \"description\": \"...\" }.",
        "response_format": "json_object",
        "temperature": 0.4,
        "max_tokens": 4000
      }
    },
    {
      "id": "description_contract",
      "type": "utility/json_schema_validate",
      "label": "Description fits the card",
      "parameters": {
        "schema_source": "inline",
        "schema_definition": {
          "$schema": "https://json-schema.org/draft/2020-12/schema",
          "type": "object",
          "additionalProperties": false,
          "required": [
            "description"
          ],
          "properties": {
            "description": {
              "type": "string",
              "minLength": 40,
              "maxLength": 170
            }
          }
        },
        "mode": "fail"
      }
    },
    {
      "id": "description",
      "type": "utility/extract",
      "label": "Description",
      "parameters": {
        "path": "description",
        "expected_type": "text",
        "on_missing": "fail"
      }
    },
    {
      "id": "catalog_rows",
      "type": "aggregate/json",
      "label": "Wines with their descriptions",
      "parameters": {
        "jsonAggregateConfig": {
          "columns": [
            {
              "name": "code",
              "inputPort": "code",
              "type": "text"
            },
            {
              "name": "name",
              "inputPort": "name",
              "type": "text"
            },
            {
              "name": "denomination",
              "inputPort": "denomination",
              "type": "text"
            },
            {
              "name": "type",
              "inputPort": "type",
              "type": "text"
            },
            {
              "name": "vintage",
              "inputPort": "vintage",
              "type": "number"
            },
            {
              "name": "grapes",
              "inputPort": "grapes",
              "type": "text"
            },
            {
              "name": "alcohol",
              "inputPort": "alcohol",
              "type": "number"
            },
            {
              "name": "size",
              "inputPort": "size",
              "type": "number"
            },
            {
              "name": "price",
              "inputPort": "price",
              "type": "number"
            },
            {
              "name": "stock",
              "inputPort": "stock",
              "type": "number"
            },
            {
              "name": "photo",
              "inputPort": "photo",
              "type": "text"
            },
            {
              "name": "description",
              "inputPort": "description",
              "type": "text"
            }
          ]
        },
        "outputName": "catalog_rows",
        "emptyBehavior": "fail"
      }
    },
    {
      "id": "render",
      "type": "design/template_render",
      "label": "Compose the catalog",
      "parameters": {
        "template_id": "__TEMPLATE_ID__",
        "template_revision": "__TEMPLATE_REVISION__",
        "output": "both",
        "page_selection": "all",
        "missing_policy": "fail_required",
        "overflow_policy": "template",
        "max_repeat": 40
      }
    },
    {
      "id": "catalog_pdf",
      "type": "output/pdf",
      "label": "Catalog — PDF",
      "parameters": {
        "output_name": "catalog_pdf"
      }
    },
    {
      "id": "catalog_pages",
      "type": "output/json",
      "label": "Catalog — page images",
      "parameters": {
        "output_name": "catalog_pages"
      }
    },
    {
      "id": "rows_output",
      "type": "output/json",
      "label": "Wines with descriptions",
      "parameters": {
        "output_name": "catalog_rows"
      }
    },
    {
      "id": "layout_report",
      "type": "output/json",
      "label": "Layout report",
      "parameters": {
        "output_name": "layout_report"
      }
    }
  ],
  "connections": [
    {
      "from_node": "price_list",
      "from_output": "dataset",
      "to_node": "wines",
      "to_input": "dataset"
    },
    {
      "from_node": "wines",
      "from_output": "name",
      "to_node": "facts",
      "to_input": "name"
    },
    {
      "from_node": "wines",
      "from_output": "denomination",
      "to_node": "facts",
      "to_input": "denomination"
    },
    {
      "from_node": "wines",
      "from_output": "type",
      "to_node": "facts",
      "to_input": "type"
    },
    {
      "from_node": "wines",
      "from_output": "grapes",
      "to_node": "facts",
      "to_input": "grapes"
    },
    {
      "from_node": "wines",
      "from_output": "notes",
      "to_node": "facts",
      "to_input": "notes"
    },
    {
      "from_node": "wines",
      "from_output": "pairing",
      "to_node": "facts",
      "to_input": "pairing"
    },
    {
      "from_node": "facts",
      "from_output": "result",
      "to_node": "writer",
      "to_input": "prompt"
    },
    {
      "from_node": "writer",
      "from_output": "json",
      "to_node": "description_contract",
      "to_input": "document"
    },
    {
      "from_node": "description_contract",
      "from_output": "normalized_json",
      "to_node": "description",
      "to_input": "json"
    },
    {
      "from_node": "wines",
      "from_output": "code",
      "to_node": "catalog_rows",
      "to_input": "code"
    },
    {
      "from_node": "wines",
      "from_output": "name",
      "to_node": "catalog_rows",
      "to_input": "name"
    },
    {
      "from_node": "wines",
      "from_output": "denomination",
      "to_node": "catalog_rows",
      "to_input": "denomination"
    },
    {
      "from_node": "wines",
      "from_output": "type",
      "to_node": "catalog_rows",
      "to_input": "type"
    },
    {
      "from_node": "wines",
      "from_output": "vintage",
      "to_node": "catalog_rows",
      "to_input": "vintage"
    },
    {
      "from_node": "wines",
      "from_output": "grapes",
      "to_node": "catalog_rows",
      "to_input": "grapes"
    },
    {
      "from_node": "wines",
      "from_output": "alcohol",
      "to_node": "catalog_rows",
      "to_input": "alcohol"
    },
    {
      "from_node": "wines",
      "from_output": "size",
      "to_node": "catalog_rows",
      "to_input": "size"
    },
    {
      "from_node": "wines",
      "from_output": "price",
      "to_node": "catalog_rows",
      "to_input": "price"
    },
    {
      "from_node": "wines",
      "from_output": "stock",
      "to_node": "catalog_rows",
      "to_input": "stock"
    },
    {
      "from_node": "wines",
      "from_output": "photo",
      "to_node": "catalog_rows",
      "to_input": "photo"
    },
    {
      "from_node": "description",
      "from_output": "value",
      "to_node": "catalog_rows",
      "to_input": "description"
    },
    {
      "from_node": "winery",
      "from_output": "json",
      "to_node": "render",
      "to_input": "data_0"
    },
    {
      "from_node": "catalog_rows",
      "from_output": "result",
      "to_node": "render",
      "to_input": "wines"
    },
    {
      "from_node": "render",
      "from_output": "pdf",
      "to_node": "catalog_pdf",
      "to_input": "pdf"
    },
    {
      "from_node": "render",
      "from_output": "pages_manifest",
      "to_node": "catalog_pages",
      "to_input": "json"
    },
    {
      "from_node": "catalog_rows",
      "from_output": "result",
      "to_node": "rows_output",
      "to_input": "json"
    },
    {
      "from_node": "render",
      "from_output": "layout_report",
      "to_node": "layout_report",
      "to_input": "json"
    }
  ],
  "layout": {
    "nodes": {
      "price_list": {
        "x": 0,
        "y": 0
      },
      "winery": {
        "x": 0,
        "y": 520
      },
      "wines": {
        "x": 420,
        "y": 0
      },
      "facts": {
        "x": 840,
        "y": 120
      },
      "writer": {
        "x": 1260,
        "y": 120
      },
      "description_contract": {
        "x": 1680,
        "y": 120
      },
      "description": {
        "x": 2100,
        "y": 120
      },
      "catalog_rows": {
        "x": 2520,
        "y": 0
      },
      "render": {
        "x": 2940,
        "y": 300
      },
      "catalog_pdf": {
        "x": 3380,
        "y": 200
      },
      "catalog_pages": {
        "x": 3380,
        "y": 360
      },
      "rows_output": {
        "x": 2940,
        "y": -120
      },
      "layout_report": {
        "x": 3380,
        "y": 520
      }
    }
  }
}
