Extract fields

To extract order IDs, amounts, or other business fields, declare rules, select the fields needed for this call, and read values by their field status. For goals and constraints alone, use the quick start without a Schema.

Start with one field

Declare orderId as a string and select it in parse. Preserve "000123" and its leading zeros. Complete installation and model configuration, save this complete file as parse-en.mjs, then run it:

import {Intent, IntentError} from '@devcodex/intent-runtime';
import {createApiExecutor} from '@devcodex/intent-runtime/adapters/api';
import {s} from 'schema-dsl/pure';

const apiKey = process.env.INTENT_API_KEY, model = process.env.INTENT_MODEL;
if (!apiKey || !model) throw new Error('Set INTENT_API_KEY and INTENT_MODEL in your environment.');
const intent = new Intent({language: 'en', executor: createApiExecutor({provider: 'openai', apiKey, model}), schema: s({orderId: s('string!').description('An order ID explicitly supplied by the user; preserve leading zeros')})});
function flatten(nodes) {return nodes.flatMap(node => [node, ...flatten(node.children)]);}
try {
  const result = await intent.parse({input: 'Look up order 000123. Do not cancel the order.', fields: ['orderId']});
  console.log(JSON.stringify(result, null, 2));
  const field = result.fieldResults.find(f => f.container === 'inputs' && f.field === 'orderId' && f.status === 'present');
  const owner = field && flatten(result.effective.intents).find(node => node.id === field.intentId);
  if (owner) console.log('Order ID:', owner.inputs.orderId);
  // The application decides what to do next; this example does not query or cancel orders.
} catch (error) {
  if (!(error instanceof IntentError)) throw error;
  console.error(JSON.stringify(error.toJSON()));
  process.exitCode = 1;
} finally {await intent.dispose();}
node parse-en.mjs

schema-dsl/pure declares a required string; fields selects only orderId. Find the present field report, then its owning intent using intentId. Reading only the first goal is insufficient. See the Schema reference for the JSON Schema equivalent and boundaries.

If the user says only “Look up the order,” inspect field status and issues. Do not manufacture an ID from a Schema. See the complete three-turn example for VIP dependencies.

Input and preconditionsValue locationCheck
Look up order 000123; select string orderIdOwning intent inputs.orderIdpresent this turn, value "000123"
State only the ID; select orderIdturn.facts.orderIdfacts ownership and intentId=null; no operation created
Amount -5; minimum=0Not written into valid inputsinvalid and the associated issue; the intent may still be complete
Explicit null note; Schema allows nullnote=null in its containerexplicit_null, distinct from absence

Download complete field-state material. Applicability also needs evidence; do not force every Schema field onto every intent.

An empty field definition with all selects no fields. New extraction is limited to selected top-level fields. fields=[] does not clear all inherited values. See the response and multi-turn guide.

VIP=true with discount=15 is valid. Changing only VIP=false can invalidate the old 15; later selecting discount and supplying 5 resolves it. A direct change to an unselected old field removes the old value without extracting the unselected replacement. Unchanged, unselected inherited values remain without claiming revalidation.

Multiple orders and falsy values

Locate values using container + intentId + path; see two complete orders. false, 0, and an empty string can be valid. Do not use if(value) as the success check. null is explicit_null only when explicitly supplied and allowed. See all eight states.

Supported rules

Use the Schema support matrix. This page covers extraction and consumption.

Formats and definition boundaries

See definition boundaries, then continue with Multi-turn changes.