Instructor
Instructor does one thing: you hand it a Pydantic model, it hands you back a validated instance. It wraps an OpenAI client, so pointing it at Hyphen is the same base URL change as everywhere else.
Code
Pin instructor>=1.15.4
Before 1.15.4, from_provider(...) silently dropped base_url and sent your
traffic to api.openai.com with a Hyphen key. It fails as a confusing auth
error rather than a routing error. Either pin the version, or use the
from_openai form further down, which was never affected.
Setup guide: this config comes from Instructor's official documentation and has not been run end to end against the gateway. Corrections to support@hyphen-solution.com.
Minimal
Code
Use Mode.TOOLS
This is the setting that matters. Instructor can extract structured data several ways, and only one of them works against the M-series.
| Mode | Mechanism | Expected on Hyphen |
|---|---|---|
Mode.TOOLS | Tool calling | Yes. Use this. |
Mode.MD_JSON | Prompt only, parses fenced JSON | Yes, fallback |
Mode.JSON | Needs response_format: json_object | No |
Mode.JSON_SCHEMA | Needs response_format: json_schema | No |
Mode.TOOLS_STRICT | Needs strict schema support | No |
Mode.TOOLS is already the default for the openai provider, so you can omit
it. Setting it explicitly documents the intent and stops a future default
change from breaking you.
If tool calling ever misbehaves on a prompt, Mode.MD_JSON is the safe
fallback because it needs no provider features at all:
Code
The classic form
Wrapping an OpenAI client yourself. Slightly more verbose, stable across versions, and makes the base URL impossible to lose.
Code
Note the model name has no openai/ prefix in this form. The prefix only
exists in from_provider's combined provider/model string.
Validation and retries
This is why Instructor is worth using. max_retries feeds validation errors
back to the model so it can repair its own output.
Code
Each retry costs tokens against your monthly cap, so keep max_retries small.
Three is plenty.
Lists and nested models
Code
Gotchas
max_tokensof 4000. Reasoning runs before the tool call carrying your object is emitted. Too low and you get a retry loop that never succeeds. See Choosing a model.- Never
Mode.JSONorMode.JSON_SCHEMA. The M-series ignoreresponse_format. - Pin
instructor>=1.15.4if you usefrom_providerwithbase_url. 429means the monthly budget is spent. Note that retries make this arrive sooner. See Handling the 429 cap.
Related
- Instructor docs
- Mode comparison
- Structured JSON output: the same job without a library.
- Pydantic AI: if you want agents as well as extraction.