Baserow review queue for AI-extracted product fields: validate before writing

Here is a small Baserow integration pattern for an AI step that extracts product attributes from text: write candidates into a review table, and keep the final catalog separate.

Disclosure: I work on Tokatlas, a multi-model API platform. The Baserow write step below is provider-independent; it starts with a JSON candidate from whichever model endpoint you use. This is an AI-assisted tutorial with synthetic example data.

1. Create a review table

Use these exact field names and types:

Field Baserow type
Source text Long text
Candidate JSON Long text
SKU candidate Single line text
Material candidate Single line text
Check result Long text
Review status Single select: needs_review, approved, rejected

Give the integration token create permission on this review table only. Keep approval edits and the final catalog outside that token’s permissions. Open your database’s generated API docs to obtain the table ID and confirm the field names.

2. Define the candidate before calling a model

Example source.txt:

SKU A-17. Material: cotton.

A prompt can request exactly sku, material, and evidence: use null for absent material, and copy evidence verbatim from the source. Treat the source as data, not as instructions.

Create candidate.json with this synthetic fixture to exercise the next step independently of model output:

{"sku":"A-17","material":"cotton","evidence":"Material: cotton."}

Do not infer that valid JSON means accurate extraction. Even an exact quote may describe a different item. The code keeps every candidate in needs_review, including those that pass the shape checks.

3. Preview the row, then explicitly send it

Save this as review_row.py (Python 3, standard library only):

import json
import os
import sys
from urllib.request import Request, urlopen


def make_row(source, candidate):
    if not isinstance(candidate, dict):
        raise ValueError('Candidate must be a JSON object')
    reasons = []
    if set(candidate) != {'sku', 'material', 'evidence'}:
        reasons.append('unexpected or missing keys')
    sku = candidate.get('sku')
    material = candidate.get('material')
    evidence = candidate.get('evidence')
    if not isinstance(sku, str) or not sku.strip() or len(sku) > 100:
        reasons.append('missing or invalid sku')
        sku = ''
    if material is None:
        reasons.append('material absent')
        material = ''
    elif not isinstance(material, str) or not material.strip() or len(material) > 100:
        reasons.append('invalid material')
        material = ''
    if not isinstance(evidence, str) or not evidence.strip() or evidence not in source:
        reasons.append('evidence is not an exact source excerpt')
    return {
        'Source text': source,
        'Candidate JSON': json.dumps(candidate, ensure_ascii=False),
        'SKU candidate': sku,
        'Material candidate': material,
        'Check result': '; '.join(reasons) or 'shape checks passed; verify meaning',
        'Review status': 'needs_review',
    }


if __name__ == '__main__':
    source = open(sys.argv[1], encoding='utf-8').read()
    candidate = json.load(open(sys.argv[2], encoding='utf-8'))
    row = make_row(source, candidate)
    # Default is a local preview. --send is an explicit database write.
    if '--send' not in sys.argv[3:]:
        print(json.dumps(row, indent=2, ensure_ascii=False))
    else:
        base = os.environ['BASEROW_API_BASE'].rstrip('/')
        table = int(os.environ['BASEROW_TABLE_ID'])
        request = Request(
            f'{base}/api/database/rows/table/{table}/?user_field_names=true',
            data=json.dumps(row).encode(),
            headers={'Authorization': 'Token ' + os.environ['BASEROW_TOKEN'],
                     'Content-Type': 'application/json'},
            method='POST',
        )
        with urlopen(request, timeout=20) as response:
            print('Created row:', json.load(response)['id'])

Preview locally:

python3 review_row.py source.txt candidate.json

For an actual write, set BASEROW_API_BASE to your Baserow API origin (Cloud: https://api.baserow.io), BASEROW_TABLE_ID to the review table ID, and BASEROW_TOKEN through your server’s secret configuration. Then run:

python3 review_row.py source.txt candidate.json --send

Keep the token on the server, not in a browser widget or a shared example. Use synthetic/redacted source text while building the workflow.

4. Make the review useful

Create a view filtered to Review status = needs_review. Review the original text, candidate values and Check result together. Only a separate authorized review step should mark a row approved and move selected values into the final catalog.

Useful cases to try: material=null; evidence that is absent from the source; SKU as a number instead of text; an extra key named approved; malformed JSON. The first four should remain review candidates with a reason; malformed JSON stops before a database write.

This example does one POST per invocation, with no automatic retry. Repeating --send creates another row. If the connection times out, check the table before rerunning: the server may have accepted the first request. For a queued production integration, add a durable source/job identifier and concurrency-safe duplicate control in your worker; a check-then-create request alone is not atomic.

Baserow reference: Database API.

For people already using a review table: do you keep corrected values alongside the original candidate, or write a separate approved record? The first preserves the comparison; the second can make downstream permissions simpler.

Thanks for sharing this use case @vitayao :slightly_smiling_face: