Documentation

Overview

Validation scripts in Requestador are written in Python and are used to verify whether an AI response matches the expected structure and content before it is accepted for further processing.

A validation script is executed after the AI response is returned and before the result is used by the next step in the workflow or sent back to the calling system.

Validation helps ensure that AI-generated responses are:

  • correctly structured

  • complete

  • consistent with expected field names

  • compliant with predefined business rules

  • optionally aligned with catalog values

Validation scripts are especially useful when Requestador actions are expected to return structured JSON that will later be transformed or mapped into another system such as Pimcore.

Purpose of validation scripts

The purpose of a validation script is to determine whether a response is acceptable.

Typical validation checks include:

  • the response is valid JSON

  • required fields are present

  • field values have the expected data type

  • the response contains no unexpected fields

  • the returned value belongs to a predefined catalog

If the validation fails, the response can be rejected before it reaches the next step of the workflow.

Validation script types

Requestador supports two main validation approaches:

1. Output validation

This type of validation checks whether the returned AI response has the correct format and structure.

Typical checks include:

  • response can be parsed as JSON

  • expected fields are present

  • field values are of the expected type

  • no additional unexpected fields exist

This is the most common validation type for structured responses such as:

  • short and long descriptions

  • translated content

  • generated product fields

  • structured enrichment outputs

2. Catalog-based output validation

This type of validation checks whether returned values match a predefined set of allowed values stored in a catalog.

Typical checks include:

  • returned category exists in the catalog

  • returned classification value is allowed

  • output uses only predefined controlled vocabulary

This validation type is useful when AI output must remain within strict business-controlled options, for example:

  • category assignment

  • SEO category selection

  • brand or product type normalization

  • controlled classification workflows

Validation script basics

Validation scripts are written in Python.

A script typically works with these inputs:

  • chat_response – the raw AI response

  • catalogs – available catalog data, when catalogs are attached to the action

  • validation_response – the response object that the script updates and returns

A validation script should return a validation result indicating whether the response is valid.

Typical structure:

In most cases, the script sets:

  • validation_response["is_valid"] = True when validation succeeds

  • leaves or returns the default validation response when validation fails

Output validation

Description

Output validation checks whether the AI response has the required structure and expected field types.

This is useful when the response must match a fixed JSON schema.

Example use case

A Requestador action returns:

  • ShortDescription

  • LongDescription

Both fields must exist, and both must be strings.

Example script

What this script validates

This script checks that:

  • the AI response is valid JSON

  • the response contains exactly the expected fields

  • all returned values are strings

If any of these checks fail, the response is treated as invalid.

Typical use cases

Use output validation when:

  • the output must follow a strict JSON structure

  • fields must be present before transformation

  • Pimcore mappings depend on predictable field names

  • you want to reject malformed AI responses early

Output validation with multiple required fields

Example use case

A Requestador action returns:

  • ProductName

  • ShortDescription

  • FullDescription

All fields must exist and all values must be strings

Example script

What this script validates

This script ensures that:

  • the response can be parsed

  • all required fields are present

  • no unexpected fields are returned

  • all values are strings

This is useful for content generation workflows with multiple output fields.

Catalog-based output validation

Description

Catalog-based output validation checks whether the AI response matches values defined in an attached catalog.

This is useful when the output must be selected from a controlled list rather than generated freely.

Example use case

A Requestador action returns:

  • SeoCategory

The value must exist in the categories catalog.

Example script

What this script validates

This script checks that:

  • the response is valid JSON

  • the required field exists

  • the returned value is a string

  • the returned value exists in the attached catalog

  • no additional fields are returned

Typical use cases

Use catalog-based output validation when:

  • the AI must choose from allowed categories

  • classifications must match business-controlled values

  • free-text output is not acceptable

  • the result is later mapped into a structured system

When to use each validation type

Use output validation when:

  • you need to validate JSON structure

  • you need specific output fields

  • you need to validate data types

  • your main concern is response consistency

Use catalog-based output validation when:

  • output must match predefined allowed values

  • you use controlled vocabularies

  • classifications must be business-safe

  • AI should not invent values outside the approved set

In many workflows, these two approaches can also be combined.

For example:

  • first validate that the correct field exists

  • then validate that its value belongs to a catalog

Best practices

  • keep validation logic simple and explicit

  • validate JSON parsing first

  • define required fields clearly

  • validate data types when structured output is expected

  • use catalogs for controlled classifications

  • reject unexpected fields if strict output structure is required

  • test validation scripts with both valid and invalid examples

  • align validation logic with your transform script and Pimcore mapping

Common validation patterns

Validate JSON parsing

Use this when the response must be structured JSON:

Validate required fields

Use this when exact field presence matters:

Validate value types

Use this when all returned values must be strings:

Validate against a catalog

Use this when the returned value must come from a controlled set:

Common mistakes

Not parsing JSON first

If the script assumes valid JSON without checking, it may fail unexpectedly.

Allowing unexpected fields

If Pimcore mappings expect a fixed response structure, extra fields may cause problems later.

Not checking data types

Even when field names are correct, wrong value types can break transformations or mappings.

Using catalog validation without attaching the catalog

If the catalog is not available in the action, validation against catalog values will fail.

Overcomplicating validation

Validation should confirm correctness, not become a full business engine. Keep it focused on structure and allowed values.