Learning resourcesReviewed · Mistral AI

Mistral quickstart: get structured output with Pydantic

A short Mistral documentation quickstart that shows Python developers how to turn a free-text customer message into a validated Pydantic object. The catch is that it needs a Mistral API key and covers only one small example. It uses the Mistral Python SDK's chat.parse method with the mistral-small-latest model. According to the page, if the model's answer does not fit the schema, a validation error is raised instead of a wrong object being returned.

Researched 14 Nov 2026

In short.

This is a single-page Mistral quickstart for Python developers who want a language model to return a validated object instead of free text. Its main catch is that it is a minimal five-minute example that needs a Mistral API key. It also does not state API pricing or rate limits, and it links to further structured-output documentation. The page defines a Pydantic class named Ticket with title (str), priority (int) and customer (str). It then calls chat.parse on the Mistral SDK with model mistral-small-latest and response_format=Ticket, and reads the typed result from response.choices[0].message.parsed. The page says that if the answer does not validate, parse raises a validation error rather than returning a wrong object. The page shows the output you should expect, but it has not been confirmed that the script runs successfully or works with the current SDK release.

Researched and written by an AI model and checked by a second AI model. How it works

The scope is the complete text of the documentation page at [https://docs.mistral.ai/inference/quickstarts/get-structured-output.md]. Pages it links to, such as Structured outputs, the API key guide, uv's installation guide and the other quickstarts, are excluded. The page contains no licence or notice text. The script, the SDK import, the model response, the expected output and the validation-error behaviour are all described by the page itself. It has not been confirmed that the script runs successfully or works with the current SDK release. Pricing, SDK version, model behaviour over time and reuse terms are unknown from this evidence.

The overview

What this resource is

This is one documentation page titled Quickstart: get structured output, published by Mistral at [https://docs.mistral.ai/inference/quickstarts/get-structured-output.md]. It sits in the inference quickstarts section of the Mistral docs. The page describes itself as a way to extract a validated Python object from free text with a Pydantic schema in about 5 minutes.

It is teaching material for one feature of the Mistral API, not a library, tool or model, so it is classed as a learning resource. The captured page does not name an author, a publication date, a page version or an SDK version.

Overall assessment

The page provides prerequisites, setup commands, a script and expected output. It is laid out as a path from an empty folder to a typed Python object, ending with one run command. For a developer who already has a Mistral account, it is a quick way to see how structured output works in the Mistral SDK.

It is deliberately narrow. It shows one schema, one model and one prompt. Apart from saying that a validation error is raised, it does not cover error handling. It also does not cover nested or optional fields, retries, token use, pricing, rate limits, or how structured output behaves on harder inputs. Treat it as a starting point, not a full guide. The page shows the output you should expect, but it has not been confirmed that the script runs successfully or works with the current SDK release. The claims about its output come from the page itself.

Who it is for

It suits developers who write Python and want machine-readable results from a language model, for example when pulling fields out of support messages, emails or forms. The page uses a customer support message as its example. Beginners can follow it if they are comfortable with a terminal, environment variables and basic Python classes. The page does not explain what Pydantic is, so a complete beginner may need to read about it elsewhere.

It is less useful for people who use another language or SDK, who want to compare providers, or who need production guidance. The page gives no TypeScript, curl or other examples, and the captured text does not say whether other SDKs offer an equivalent method.

What it shows you how to do

The page shows how to describe the fields you want as a Pydantic BaseModel and have the Mistral model fill them from a message. In the example, a message from Ada at Acme reporting that a checkout page is down becomes a Ticket with a title, an integer priority and a customer name. The script then prints the object and reads priority as a Python integer.

The page states that the returned values can vary slightly between runs but always match the types of Ticket, and that a result that fails validation raises an error. It points to a separate Structured outputs page for JSON mode and JSON schemas, so those routes are not covered here.

Using it

What you need

The page lists two prerequisites. The first is a Mistral API key, and it links to a separate page on creating one. The second is Python 3.10 or later together with uv, the Python package and project tool, with a link to uv's installation guide. The script imports pydantic, but the page explicitly installs only mistralai. This page does not say how Pydantic gets installed.

The script needs network access to Mistral's API and the MISTRAL_API_KEY environment variable. The page does not state any account tier, region or quota requirement, and does not state which operating systems it was tried on.

How it works

According to the page, chat.parse sends the schema of the Ticket class along with the request, then parses and validates the model's answer. The caller passes the Pydantic class itself as response_format, and the typed object comes back on response.choices[0].message.parsed. The page does not explain how the schema is turned into a request, whether the server enforces it while generating, or whether the SDK validates it only after the response arrives. Those details are unknown from this page.

One detail is visible in the code. The Ticket class declares priority as a plain int, while the 1 (urgent) to 3 (low) range appears only in the prompt text. So the schema as written checks the type but not the range. A model answer of 7 would still pass type validation. The page does not discuss this, so a developer who needs a bounded range would have to add a constraint to the schema themselves. This point comes from the code as written, not from anything the page says.

Setup steps

The page gives three setup commands. First, uv init structured-output --python 3.12 creates a project and the shell moves into that folder. Second, uv add mistralai installs the Mistral SDK. Third, export MISTRAL_API_KEY with your key sets the environment variable the script reads. The script is then saved as structured.py and run with uv run structured.py.

The page does not pin an SDK version. The import line is from mistralai.client import Mistral. The package may change over time, and the page does not say which release the example was written for. If the import or chat.parse does not work with the SDK version you get, check the current Mistral SDK documentation.

Worked example from the page

The script defines class Ticket(BaseModel) with title: str, priority: int and customer: str. It creates a Mistral client from the API key and calls client.chat.parse with model mistral-small-latest. The single user message is: Ada from Acme writes: our checkout page is down, please fix it urgently. Extract a support ticket with a priority from 1 (urgent) to 3 (low). The script then prints the parsed ticket and the priority.

The page shows this expected output: title='Checkout page is down' priority=1 customer='Acme', followed by Priority: 1. It adds that values can vary slightly between runs. This is the page's own expected result. It has not been confirmed that the script produces it with the current SDK release.

Assessment & evidence

Limitations and risks

The page covers one schema with three simple fields and one sample message. It gives no guidance on nested models, lists, optional fields, long inputs, messages in other languages, or what happens when the input does not contain a customer or title. It does not say how often validation fails or how to handle a validation error beyond noting that one is raised.

The model name mistral-small-latest ends in latest. The page does not say what it points to or whether it changes, so results and output wording may differ over time. The page itself says values vary between runs. Anyone sending real customer messages to an external API should also check data handling and privacy terms, which this page does not discuss.

The page shows the output you should expect, but it has not been confirmed that the script runs as written or works with the current SDK release. The page gives no accuracy or reliability measure for the extraction.

Why this assessment

The assessment rests on the full text of the page. The page has a clear goal, prerequisites, ordered steps, complete code and an expected result, so it is a step-by-step how-to and not a marketing page. The mechanism and limits above come from what the code and text actually say. Where the page is silent, as on pricing, SDK versions, enforcement details and licence, these points are treated as unknown.

The page's code declares priority as a plain integer and gives the 1 to 3 range only in the prompt. That point comes from the code as written. The page itself does not discuss it.

Alternatives and next steps

The page itself points to a Structured outputs page for JSON mode and JSON schemas, which is the other route to structured results with Mistral. It also points to quickstarts on calling your own functions and running a batch job. Those linked pages are separate from this quickstart, so beyond their titles, what they contain is unknown here.

The page does not compare Mistral's approach with other providers' structured output features or with validation libraries applied to free-text replies. A reader who wants to compare approaches would need to consult other sources.

Evidence behind this report

The source is the full text of the Mistral documentation page at [https://docs.mistral.ai/inference/quickstarts/get-structured-output.md]. Pages it links to, such as Structured outputs, the API key guide, uv's installation guide and the other quickstarts, are not part of it. All statements here about the page's content come from that text.

The expected output and the validation behaviour are claims the page itself makes. The page gives sample code with no version and makes no explicit statement about which SDK versions it works with, so compatibility with the current SDK is unknown. It has also not been confirmed that the script runs successfully.

Access & freshness

Costs

The page states no access price or API pricing; running costs are unknown. It also states no free tier and no token or rate limits. The example needs a Mistral API key and makes one model request per run, so it implies usage on a Mistral account. The page does not say whether that usage is billed, free or limited. Check Mistral's pricing and account pages before relying on it.

The page does not state the cost of the other tools it names, such as uv and the SDK.

Rights and reuse

The page text contains no licence statement, copyright notice or reuse terms. Whether you may copy or redistribute the page text or the example script is therefore unknown.

The page does not set out any terms that govern use of the Mistral API. Check those separately before reusing the example in your own work.

Freshness

The page was captured on 14 November 2026. The captured text carries no publication or update date and no SDK or model version. The mistral-small-latest model name and the unpinned SDK install mean the example may behave differently as Mistral updates them. Beyond the capture date, it is not known how current this text is compared with the live documentation. Check the live page and the current SDK reference before depending on the exact code.

What to do next

If you already have a Mistral API key and Python 3.10 or later, follow the page in a fresh uv project and compare your output with the page's expected output. Then try changing the Ticket class. For example, add a constraint on priority so that only 1 to 3 is accepted, since the page's schema does not enforce that range.

Before using it with real data, check Mistral's pricing, rate limits and data-handling terms, and test how your code handles the validation error. For a full picture of structured output, read the Structured outputs page that this quickstart links to.

Evidence for this report

selected-page.txtselected · checked 2026-11-14