Skip to main content
Instructor patches the OpenAI client to return typed Pydantic objects instead of raw completions. Since dottxt exposes an OpenAI-compatible endpoint, you can use Instructor on top of the OpenAI Python SDK. For dottxt, the important detail is to use Instructor in JSON mode so your response_model is translated into JSON Schema and sent through dottxt structured generation, rather than relying on tool-calling behavior. Instructor has excellent documentation covering advanced patterns like validation, retries, partial streaming, and multi-modal extraction. This page covers the dottxt-specific setup. Refer to the Instructor docs for everything else.

Install

Configure

Create an OpenAI client pointed at dottxt, then patch it with Instructor in JSON mode:

Basic usage

Define a Pydantic model and pass it as response_model. Instructor will derive JSON Schema from the model, send that schema to dottxt, and validate the response back into a Pydantic object:
Instructor handles schema generation, request construction, and response parsing for you. The underlying API call still uses the same dottxt structured generation path described in API Overview and Pydantic Authoring.

What Instructor sends to dottxt

Under the hood, the Contact model above is converted into JSON Schema and sent to dottxt as structured output constraints:

Nested models and enums

Streaming partial results

Use create_partial to yield progressively-complete model instances as tokens stream in:

Notes

  • Use mode=instructor.Mode.JSON with dottxt so Instructor goes through the structured output path instead of defaulting to tool calling.
  • ConfigDict(extra="forbid") is useful when you want additionalProperties: false in the generated schema.
  • create_with_completion() returns both the parsed model and the raw completion, useful for inspecting token usage.
  • See the Pydantic authoring guide for how to write effective schemas.