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.
{
"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.
- Python
- TypeScript
- cURL
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"]))
import { readFileSync } from "node:fs";
const request = {
"input": "Book February 29, 2024 at 10:00 UTC. Reference AB-1234. Note: Window seat.",
"schema": JSON.parse(readFileSync("booking.schema.json", "utf8")),
};
const response = await fetch(
"https://api.blatent.ai" + "/v1/resolve",
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.BLATENT_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify(request),
signal: AbortSignal.timeout(195_000),
},
);
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
console.log(JSON.stringify((await response.json()).output));
set -eu
body=$(jq -n --argjson body '{"input":"Book February 29, 2024 at 10:00 UTC. Reference AB-1234. Note: Window seat."}' \
--slurpfile f0 'booking.schema.json' \
'$body | setpath(["schema"]; $f0[0])')
curl --fail-with-body --silent --show-error \
"https://api.blatent.ai/v1/resolve" \
-H "Authorization: Bearer $BLATENT_API_KEY" \
-H 'Content-Type: application/json' \
--data-binary "$body"
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.