← All procedures

llm.structured

Send a prompt and a JSON Schema to a language model and give a value that the schema accepts

CLI
Package
@procedures/llm · README
Path
["llm","structured"]
CLI
mark llm structured --prompt <string> --schema <object>
As data
{"$proc":["llm","structured"],"input":{}}
Tags
llm, anthropic, json-schema

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/llm/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["llm","structured"], { prompt: "<prompt>", schema: {} });
console.log(JSON.stringify(result));

From the command line

$ mark llm structured --prompt <string> --schema <object>

As data, in a program

{
  "$proc": ["llm", "structured"],
  "input": { "prompt": "<prompt>", "schema": {} }
}

Input

FieldTypeRequiredDefaultDescription
promptstringyesThe text of the user
systemstringnoThe system text: the instructions to the model
modelstringnoThe model (default: the model of the module, claude-sonnet-5-5)
maxTokensintegernoThe most tokens of the output, with the thinking (default 16000)
temperaturenumbernoThe temperature, 0 to 1. Some models accept only the default
effort"low" | "medium" | "high" | "xhigh" | "max"noThe effort of the model (default: the default of the model)
timeoutMsintegernoThe time limit of each request, in milliseconds (default 600000)
fallbackbooleannoTrue: the API runs a declined request again on its fallback model (default: the option of the module, true)
schemaobjectyesThe JSON Schema of the value
constrainedbooleannoTrue (default): the API constrains the output to the schema. False: the system text gives the schema
retriesintegernoThe new tries after an answer that is not valid, 0 to 2 (default 2)
requestRetriesintegernoThe new tries after a retryable error (429, 529, 5xx, a connection error), 0 to 10 (default: the option of the module, 2)

Output

FieldTypeRequiredDefaultDescription
valueanyyesThe value: the schema accepts it
modelstringyesThe model that gave the value
attemptsintegeryesThe number of calls to the model
usageobjectyesThe tokens of the call
uncheckedstring[]yesThe keywords of the schema that the check does not examine fully
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "prompt": {
        "type": "string",
        "minLength": 1,
        "maxLength": 4000000,
        "description": "The text of the user"
      },
      "system": {
        "description": "The system text: the instructions to the model",
        "type": "string",
        "maxLength": 4000000
      },
      "model": {
        "description": "The model (default: the model of the module, claude-sonnet-5-5)",
        "type": "string",
        "minLength": 1,
        "maxLength": 200,
        "pattern": "^[A-Za-z0-9][A-Za-z0-9._:@/-]*$"
      },
      "maxTokens": {
        "description": "The most tokens of the output, with the thinking (default 16000)",
        "type": "integer",
        "minimum": 1,
        "maximum": 64000
      },
      "temperature": {
        "description": "The temperature, 0 to 1. Some models accept only the default",
        "type": "number",
        "minimum": 0,
        "maximum": 1
      },
      "effort": {
        "description": "The effort of the model (default: the default of the model)",
        "type": "string",
        "enum": [
          "low",
          "medium",
          "high",
          "xhigh",
          "max"
        ]
      },
      "timeoutMs": {
        "description": "The time limit of each request, in milliseconds (default 600000)",
        "type": "integer",
        "exclusiveMinimum": 0,
        "maximum": 3600000
      },
      "fallback": {
        "description": "True: the API runs a declined request again on its fallback model (default: the option of the module, true)",
        "type": "boolean"
      },
      "schema": {
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {},
        "description": "The JSON Schema of the value"
      },
      "constrained": {
        "description": "True (default): the API constrains the output to the schema. False: the system text gives the schema",
        "type": "boolean"
      },
      "retries": {
        "description": "The new tries after an answer that is not valid, 0 to 2 (default 2)",
        "type": "integer",
        "minimum": 0,
        "maximum": 2
      },
      "requestRetries": {
        "description": "The new tries after a retryable error (429, 529, 5xx, a connection error), 0 to 10 (default: the option of the module, 2)",
        "type": "integer",
        "minimum": 0,
        "maximum": 10
      }
    },
    "required": [
      "prompt",
      "schema"
    ]
  },
  "output": {
    "type": "object",
    "properties": {
      "value": {
        "description": "The value: the schema accepts it"
      },
      "model": {
        "type": "string",
        "description": "The model that gave the value"
      },
      "attempts": {
        "type": "integer",
        "minimum": -9007199254740991,
        "maximum": 9007199254740991,
        "description": "The number of calls to the model"
      },
      "usage": {
        "type": "object",
        "properties": {
          "inputTokens": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991,
            "description": "The tokens of the input that the cache did not have"
          },
          "outputTokens": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991,
            "description": "The tokens of the output, with the thinking"
          },
          "cacheReadInputTokens": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991,
            "description": "The tokens of the input from the cache"
          },
          "cacheCreationInputTokens": {
            "type": "integer",
            "minimum": -9007199254740991,
            "maximum": 9007199254740991,
            "description": "The tokens of the input that went into the cache"
          }
        },
        "required": [
          "inputTokens",
          "outputTokens",
          "cacheReadInputTokens",
          "cacheCreationInputTokens"
        ],
        "additionalProperties": false,
        "description": "The tokens of the call"
      },
      "unchecked": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "description": "The keywords of the schema that the check does not examine fully"
      }
    },
    "required": [
      "value",
      "model",
      "attempts",
      "usage",
      "unchecked"
    ],
    "additionalProperties": false
  }
}