Skip to main content

Booking extraction

Extract three values with different constraints: a patterned identifier, a date-time and a bounded string. Use this pattern when your application needs usable values from a written request, rather than a free-form response.

Define the extracted fields​

Save the schema below. The descriptions tell the model what to extract; pattern, format and length constraints define legal values.

booking.schema.json
{
"type": "object",
"properties": {
"reference": {
"type": "string",
"pattern": "^[A-Z]{2}-[0-9]{4}$",
"description": "Copy the booking reference exactly."
},
"scheduled_at": {
"type": "string",
"format": "date-time",
"description": "The requested start instant including its timezone."
},
"note": {
"type": "string",
"minLength": 1,
"maxLength": 80,
"description": "Copy only the note supplied by the customer."
}
},
"required": ["reference", "scheduled_at", "note"],
"additionalProperties": false
}

Extract from a message​

Before you run this example

Call https://api.blatent.ai from your server. Set your API key in the same terminal where you run the example:

export BLATENT_API_KEY='YOUR_SERVICE_KEY'

Python requires Python 3.10+ and HTTPX:

python -m pip install "httpx>=0.28,<1"

TypeScript requires Node.js 24+ and uses its built-in fetch. The cURL examples require curl and jq.

Save the displayed files and the selected client in one directory. Run the client there with python example.py, node example.ts or bash example.sh. Downloads use the example's name in place of example.

import json
import os
from pathlib import Path
import httpx

request = {
"input": "Book February 29, 2024 at 10:00 UTC. Reference AB-1234. Note: Window seat.",
"schema": json.loads(Path("booking.schema.json").read_text(encoding="utf-8")),
}
with httpx.Client(
base_url="https://api.blatent.ai",
headers={"Authorization": f"Bearer {os.environ['BLATENT_API_KEY']}"},
timeout=195,
) as client:
response = client.post("/v1/resolve", json=request)
response.raise_for_status()
print(json.dumps(response.json()["output"]))

Illustrative output:

{"reference":"AB-1234","scheduled_at":"2024-02-29T10:00:00Z","note":"Window seat."}

The schema enforces a legal timestamp and reference shape. Your application should also check that the intended booking and reference were interpreted correctly. Include ambiguous dates, timezone changes and exact-copy cases in your evaluation.

See constrained strings for the interpretation of formats and character lengths.