Skip to content

Commit d1694b1

Browse files
committed
docs(modes): add migration guide
1 parent 2469443 commit d1694b1

File tree

6 files changed

+170
-178
lines changed

6 files changed

+170
-178
lines changed

docs/api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ description: Explore the comprehensive API reference with details on instructors
55

66
# API Reference
77

8+
Core modes are the recommended default. Legacy provider-specific modes still
9+
work but are deprecated and will show warnings. See the
10+
[Mode Migration Guide](concepts/mode-migration.md) for details.
11+
812
::: instructor.from_provider
913

1014
::: instructor.dsl.validators

docs/concepts/from_provider.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,16 @@ client = instructor.from_provider(
189189

190190
## Default Modes
191191

192-
Each provider uses a recommended default mode:
192+
Each provider uses a recommended default **core** mode:
193193

194-
- **OpenAI**: `Mode.TOOLS` (function calling)
195-
- **Anthropic**: `Mode.ANTHROPIC_TOOLS` (tool use)
196-
- **Google**: `Mode.GENAI_TOOLS` (function calling)
197-
- **Ollama**: `Mode.TOOLS` (if model supports it) or `Mode.JSON`
198-
- **Others**: Provider-specific defaults
194+
- **OpenAI**: `Mode.TOOLS`
195+
- **Anthropic**: `Mode.TOOLS`
196+
- **Google**: `Mode.TOOLS` or `Mode.JSON` based on the model
197+
- **Ollama**: `Mode.TOOLS` (if supported) or `Mode.JSON`
198+
- **Others**: `Mode.TOOLS` or `Mode.MD_JSON` depending on capability
199+
200+
Legacy provider-specific modes still work, but they are deprecated.
201+
See the [Mode Migration Guide](./mode-migration.md) for details.
199202

200203
You can override these defaults with the `mode` parameter.
201204

docs/concepts/mode-migration.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
---
2+
title: Mode Migration Guide
3+
description: Migrate from provider-specific modes to the core modes in Instructor.
4+
---
5+
6+
# Mode Migration Guide
7+
8+
This guide helps you move from provider-specific modes to the core modes.
9+
Core modes work across providers and are the recommended choice for new code.
10+
11+
## Core Modes
12+
13+
These are the core modes you should use:
14+
15+
- `TOOLS`: Tool or function calling
16+
- `JSON_SCHEMA`: Native schema support when a provider has it
17+
- `MD_JSON`: JSON extracted from text or code blocks
18+
- `PARALLEL_TOOLS`: Multiple tool calls in one response
19+
- `RESPONSES_TOOLS`: OpenAI Responses API tools
20+
21+
## Quick Mapping
22+
23+
Use this table to replace legacy modes:
24+
25+
| Legacy Mode | Core Mode |
26+
|------------|-----------|
27+
| `FUNCTIONS` | `TOOLS` |
28+
| `TOOLS_STRICT` | `TOOLS` |
29+
| `ANTHROPIC_TOOLS` | `TOOLS` |
30+
| `ANTHROPIC_JSON` | `MD_JSON` |
31+
| `COHERE_TOOLS` | `TOOLS` |
32+
| `COHERE_JSON_SCHEMA` | `JSON_SCHEMA` |
33+
| `XAI_TOOLS` | `TOOLS` |
34+
| `XAI_JSON` | `MD_JSON` |
35+
| `MISTRAL_TOOLS` | `TOOLS` |
36+
| `MISTRAL_STRUCTURED_OUTPUTS` | `JSON_SCHEMA` |
37+
| `BEDROCK_TOOLS` | `TOOLS` |
38+
| `BEDROCK_JSON` | `MD_JSON` |
39+
40+
## Example: Anthropic
41+
42+
**Before:**
43+
44+
```python
45+
import instructor
46+
from instructor import Mode
47+
48+
client = instructor.from_provider(
49+
"anthropic/claude-3-5-haiku-latest",
50+
mode=Mode.ANTHROPIC_TOOLS,
51+
)
52+
```
53+
54+
**After:**
55+
56+
```python
57+
import instructor
58+
from instructor import Mode
59+
60+
client = instructor.from_provider(
61+
"anthropic/claude-3-5-haiku-latest",
62+
mode=Mode.TOOLS,
63+
)
64+
```
65+
66+
## Example: Bedrock
67+
68+
**Before:**
69+
70+
```python
71+
import instructor
72+
from instructor import Mode
73+
74+
client = instructor.from_provider(
75+
"bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0",
76+
mode=Mode.BEDROCK_TOOLS,
77+
)
78+
```
79+
80+
**After:**
81+
82+
```python
83+
import instructor
84+
from instructor import Mode
85+
86+
client = instructor.from_provider(
87+
"bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0",
88+
mode=Mode.TOOLS,
89+
)
90+
```
91+
92+
## Notes
93+
94+
- Legacy modes still work but show a deprecation warning.
95+
- Use core modes for new code and docs.
96+
- See [Mode Comparison](../modes-comparison.md) for details.

docs/integrations/bedrock.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pip install "instructor[bedrock]"
1919

2020
- [Getting Started](../getting-started.md) - Quick start guide
2121
- [from_provider Guide](../concepts/from_provider.md) - Detailed client configuration
22+
- [Mode Migration Guide](../concepts/mode-migration.md) - Move to core modes
2223
- [Provider Examples](../index.md#provider-examples) - Quick examples for all providers
2324
- [AWS Integration Guide](../examples/index.md#aws-integration) - More AWS examples
2425

@@ -39,7 +40,7 @@ client = instructor.from_provider("bedrock/anthropic.claude-3-5-sonnet-20241022-
3940
# The auto client automatically handles:
4041
# - AWS credential detection from environment
4142
# - Region configuration (defaults to us-east-1)
42-
# - Mode selection based on model (Claude models use BEDROCK_TOOLS)
43+
# - Mode selection based on model (Claude models use TOOLS)
4344
```
4445

4546
## Deprecation Notice
@@ -122,10 +123,13 @@ print(user)
122123

123124
## Supported Modes
124125

125-
AWS Bedrock supports the following modes with Instructor:
126+
AWS Bedrock supports the following **core** modes:
126127

127-
- `BEDROCK_TOOLS`: Uses function calling for models that support it (like Claude models)
128-
- `BEDROCK_JSON`: Direct JSON response generation
128+
- `TOOLS`: Uses function calling for models that support it (like Claude models)
129+
- `MD_JSON`: Direct JSON response generation (text extraction fallback)
130+
131+
> Legacy modes (`BEDROCK_TOOLS`, `BEDROCK_JSON`) are deprecated and map to the core
132+
> modes above. Use `TOOLS` or `MD_JSON` in new code.
129133
130134
```python
131135
import boto3
@@ -134,11 +138,11 @@ from instructor import Mode
134138
from pydantic import BaseModel
135139

136140
# Use from_provider for simplified setup
137-
client = instructor.from_provider("bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0", mode=Mode.BEDROCK_TOOLS)
141+
client = instructor.from_provider("bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0", mode=Mode.TOOLS)
138142

139143
# Or if you need to use a custom boto3 client:
140144
# bedrock_client = boto3.client('bedrock-runtime')
141-
# client = instructor.from_provider("bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0", client=bedrock_client, mode=Mode.BEDROCK_TOOLS)
145+
# client = instructor.from_provider("bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0", client=bedrock_client, mode=Mode.TOOLS)
142146

143147
class User(BaseModel):
144148
name: str
@@ -314,7 +318,7 @@ bedrock_client = boto3.client(
314318
client = instructor.from_provider(
315319
"bedrock/anthropic.claude-3-5-sonnet-20241022-v2:0",
316320
client=bedrock_client,
317-
mode=instructor.Mode.BEDROCK_TOOLS
321+
mode=instructor.Mode.TOOLS
318322
)
319323

320324
# Advanced inference configuration

0 commit comments

Comments
 (0)