- Parsing API responses
- Extracting information from natural language
- Scanning images for text
ctx.llm.structured()
call.
Usage
Text Processing
This is a simple example of how to get a structured output within a workflow.Image Processing
You can also process images and extract structured information from them by providing a base64 encoded image string to theinput
field.
Configuration
Input The input is always a string. If you need to process an image, you can pass a base64 encoded image string to theinput
field.
Schema
The schema is a JSON schema that describes the structure of the output you want. Or in TypeScript, a Zod schema.
Instructions
Sometimes, you may want to provide additional instructions to the LLM to help it understand the structure of the output you want.
You can do this by providing the instructions
field.
Model Selection
By defaultctx.llm.structured
will use the Claude Sonnet 3.5 model provided by Inferable.
However, this is intended for testing only. You can specify your own LLM provider details when calling ctx.llm.structured
.
Semantics
JSON Schema Descriptions
Inferable will use the JSON schema descriptions (or Zod schema descriptions) to provide the LLM with additional context about the structure of the output you want.Retries
If the LLM returns a structured output that does not conform to the schema you provided, Inferable will retry the request 2 more times, providing the LLM with the previous error. If the LLM still returns an output that does not conform to the schema,ctx.llm.structured()
will throw an error.