Use this file to discover all available pages before exploring further.
Structured Outputs ensure that models follow your supplied JSON schema. Portkey supports this for Claude models on AWS Bedrock using a unified response_format interface.Define object schemas using Pydantic (Python) or Zod (JavaScript) to extract structured information from unstructured text.
This feature is supported on Claude 3 and later models hosted on AWS Bedrock.
This approach provides type hinting and automatic validation.
from portkey_ai import Portkeyfrom pydantic import BaseModelclass Step(BaseModel): explanation: str output: strclass MathReasoning(BaseModel): steps: list[Step] final_answer: strportkey = Portkey( api_key="PORTKEY_API_KEY",)# Use .parse() for automatic parsingcompletion = portkey.chat.completions.parse( model="@bedrock/us.anthropic.claude-sonnet-4-5-20250929-v1:0", messages=[ {"role": "system", "content": "You are a helpful math tutor. Guide the user through the solution step by step."}, {"role": "user", "content": "how can I solve 8x + 7 = -23"} ], response_format=MathReasoning)print(completion.choices[0].message.parsed)