1import { ApifyClient } from 'apify-client';
2
3
4
5const client = new ApifyClient({
6 token: '<YOUR_API_TOKEN>',
7});
8
9
10const input = {
11 "schema": {
12 "type": "object",
13 "required": [
14 "sku",
15 "name",
16 "price",
17 "inStock"
18 ],
19 "additionalProperties": false,
20 "properties": {
21 "sku": {
22 "type": "string",
23 "pattern": "^[A-Z]{3}-\\d{4}$"
24 },
25 "name": {
26 "type": "string",
27 "minLength": 1
28 },
29 "price": {
30 "type": "number",
31 "minimum": 0
32 },
33 "inStock": {
34 "type": "boolean"
35 },
36 "status": {
37 "type": "string",
38 "enum": [
39 "active",
40 "discontinued"
41 ]
42 }
43 }
44 },
45 "items": [
46 {
47 "sku": "ABC-1234",
48 "name": "Widget",
49 "price": 9.99,
50 "inStock": true,
51 "status": "active"
52 },
53 {
54 "sku": "ABC-5678",
55 "name": "Gizmo",
56 "price": "$19.99",
57 "inStock": "yes",
58 "status": "Active"
59 },
60 {
61 "sku": "nope",
62 "name": "",
63 "price": -3,
64 "hallucinatedField": "invented by the model"
65 }
66 ]
67};
68
69
70const run = await client.actor("broomwagon/llm-output-guard").call(input);
71
72
73console.log('Results from dataset');
74console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
75const { items } = await client.dataset(run.defaultDatasetId).listItems();
76items.forEach((item) => {
77 console.dir(item);
78});
79
80