Skip to main content
Instructor can accept structured data as input, not just raw text. This enables powerful object-to-object transformations where the LLM acts as an intelligent mapping and enrichment layer between two data shapes.

Basic Usage

Use withInput() to pass arrays or objects as input. Instructor serializes them into messages automatically.

Object-to-Object Transformation

The most common use case is transforming one object into another, using the LLM to interpret, translate, or enrich the data along the way.
The input object is serialized into the message content, and the LLM produces a new object of the specified response model class. The prompt parameter provides instructions for how to transform the data.

Array Input

Arrays work the same way. This is useful when your source data comes from a database query, API response, or form submission.

String Input

Plain strings are also accepted. In this case, withInput() behaves the same as withMessages().

When to Use Structure-to-Structure

This pattern is most valuable when:
  • Translating or localizing structured content while preserving the data shape
  • Enriching existing data with LLM-generated content (e.g., adding descriptions, summaries, or tags)
  • Mapping between different schemas, using the LLM to handle ambiguity that rule-based mapping cannot
  • Normalizing messy or inconsistent structured data into a clean format