This page lists a series of tutorials for using Pydantic with different LLMs on OpenRouter
Three things to note:
1 While OpenRouter does provide a way to specify the schema as one of the API parameters, I have not had much luck getting it to work with the LLMs I have tried. It could have been an error on my part, but there are two more points to consider.
2 Not all LLMs support structured outputs (via OpenRouter’s API), but you can hard code the JSON schema into the prompt itself to get around this problem
3 It is much easier to customize and “engineer” the prompt using my system compared to the API parameter exposed by OpenRouter
This basic setup applies to all the tutorials listed below
While you should be able to follow along with all the tutorials by reading the code I have published (and getting a bit of help from some LLM if necessary), you can also download the entire Python project from the course below (open the project in PyCharm inside a venv and pip install the requirements)
This tutorial explains how to use a Pydantic schema to extract structured data using DeepSeek V3.1 Terminus. Please read this tutorial first to understand the basic setup Code: import os import json import requests import datetime from inputs import get_input_text from system import system_instruction_1 as system_instruction from schema import VAERSReport …
This tutorial explains how to use a Pydantic schema to extract structured data using OpenGVLab: InternVL3 78B. Please read this tutorial first to understand the basic setup Code: import os import json import requests import time from inputs import get_input_text from system import system_instruction_1 as system_instruction from schema import VAERSReport …
This tutorial explains how to use a Pydantic schema to extract structured data using Arcee AI: AFM 4.5B. Please read this tutorial first to understand the basic setup Code: import os import json import requests import time from inputs import get_input_text from system import system_instruction_1 as system_instruction from schema import …
This tutorial explains how to use a Pydantic schema to extract structured data using Qwen3 Coder Plus. Please read this tutorial first to understand the basic setup Code: import os import json import requests import time from inputs import get_input_text from system import system_instruction_1 as system_instruction from schema import VAERSReport …
This tutorial explains how to use a Pydantic schema to extract structured data using Qwen3 Coder Flash. Please read this tutorial first to understand the basic setup Code: import os import json import requests import time from inputs import get_input_text from system import system_instruction_1 as system_instruction from schema import VAERSReport …
This tutorial explains how to use a Pydantic schema to extract structured data using xAI Grok 4 Fast. The code uses the free model, but you can just change the model name to the paid one once it becomes available. Please read this tutorial first to understand the basic setup …