# Clarification on how Pydantic schema descriptions are used in with\_structured\_output

**URL:** <https://forum.langchain.com/t/clarification-on-how-pydantic-schema-descriptions-are-used-in-with-structured-output/1612>\
**Category:** LangChain\
**Tags:** python-help\
**Created:** [September 22, 2025, 8:41am UTC](https://forum.langchain.com/t/clarification-on-how-pydantic-schema-descriptions-are-used-in-with-structured-output/1612 "2025-09-22T08:41:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dds](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@dds](https://forum.langchain.com/u/dds)\
**Post date:** [September 22, 2025, 8:41am UTC](https://forum.langchain.com/t/clarification-on-how-pydantic-schema-descriptions-are-used-in-with-structured-output/1612/1 "2025-09-22T08:41:09Z")

</div>

Hi all,

I’ve been digging into how `with_structured_output` works with Pydantic models, and I came across this note in the [docs](https://python.langchain.com/docs/how_to/structured_output/?utm_source=chatgpt.com#pydantic-class):

> _“Beyond just the structure of the Pydantic class, the name of the Pydantic class, the docstring, and the names and provided descriptions of parameters are very important. Most of the time, `with_structured_output` is using a model’s function/tool-calling API, and you can effectively think of all of this information as being added to the model prompt.”_

From what I can tell in the source code:

- `with_structured_output` relies on [PydanticOutputParser](https://github.com/langchain-ai/langchain/blob/master/libs/core/langchain_core/output_parsers/pydantic.py).

- That parser’s `get_format_instructions` calls `pydantic_object.model_json_schema()` to generate the schema (including field descriptions).

- These instructions are then embedded into the prompt with `_PYDANTIC_FORMAT_INSTRUCTIONS`.

What I’m unclear on is the phrase _“most of the time”_.

- Is `get_format_instructions` always injected into the final prompt when using `with_structured_output`?

- Or are there specific contexts (e.g. when wrapped in certain tools or chains, or when using the function-calling API differently) where the schema isn’t passed through the prompt?

I’d love to understand in practice when the schema descriptions are guaranteed to be included vs. when they might not be.

Thanks!

---

<div class="post-metadata">

**Author:** ![pawel-twardziak](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/pawel-twardziak/32/960_2.png) [@pawel-twardziak](https://forum.langchain.com/u/pawel-twardziak)\
**Post date:** [September 22, 2025, 4:10pm UTC](https://forum.langchain.com/t/clarification-on-how-pydantic-schema-descriptions-are-used-in-with-structured-output/1612/2 "2025-09-22T16:10:41Z")

</div>

Short version: No - get\_format\_instructions() is not always injected into the prompt. with\_structured\_output picks the best available strategy per model/provider:

- Most of the time: If the chat model supports native structured outputs (tool/function-calling or JSON/response-format modes), LangChain passes the Pydantic schema via the model’s API (tools/response\_format), not as prompt text. The class name, docstring, and field descriptions become the tool/function definition metadata the model sees.

- Fallback: If the model lacks native structured output, LangChain falls back to a prompt+parser approach and injects PydanticOutputParser.get\_format\_instructions() (which uses \_PYDANTIC\_FORMAT\_INSTRUCTIONS) into the prompt.

So:

- Is get\_format\_instructions always injected? - No. It’s only injected in the fallback path.

- When isn’t it injected? - When the model supports tool/function-calling or JSON/response-format. In those cases the schema is sent via request parameters, not prompt text.

- When is it guaranteed to be included? - When using text-only models without native structured output (or when you explicitly force the prompt+parser route).

How to verify in practice:

- Check the request in your traces: you’ll either see a tools/response\_format payload (native path) or a prompt containing the format instructions (fallback path).

- In LangGraph’s prebuilt agent flow, response\_format=YourModel adds a separate final LLM call for structured output; it uses the same logic: native tool/JSON when available, prompt+parser otherwise. See “Configure structured output” in the quickstart [here](https://langchain-ai.github.io/langgraph/agents/agents/#6-configure-structured-output).

If you need to force a specific path, some model wrappers expose a parameter to prefer tool-calling vs JSON mode vs prompt+parser; otherwise it’s auto-selected based on model capabilities.

---

<div class="post-metadata">

**Author:** ![dds](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@dds](https://forum.langchain.com/u/dds)\
**Post date:** [September 23, 2025, 6:40am UTC](https://forum.langchain.com/t/clarification-on-how-pydantic-schema-descriptions-are-used-in-with-structured-output/1612/3 "2025-09-23T06:40:21Z")

</div>

Thank you very much for the detailed answer! Makes totally sense!

---

<div class="post-metadata">

**Author:** ![pawel-twardziak](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/pawel-twardziak/32/960_2.png) [@pawel-twardziak](https://forum.langchain.com/u/pawel-twardziak)\
**Post date:** [September 23, 2025, 7:45pm UTC](https://forum.langchain.com/t/clarification-on-how-pydantic-schema-descriptions-are-used-in-with-structured-output/1612/4 "2025-09-23T19:45:48Z")

</div>

hi @dds

something in addition 🙂 [Structured output from LLMs: more than just prompt engineering | by Paweł Twardziak | Sep, 2025 | Medium](https://medium.com/@twardziak.p/structured-output-from-llms-more-than-just-prompt-engineering-b47408a0f8d3)

---

<div class="post-metadata">

**Author:** ![dds](https://avatars.discourse-cdn.com/v4/letter/d/ee7513/32.png) [@dds](https://forum.langchain.com/u/dds)\
**Post date:** [September 24, 2025, 6:59am UTC](https://forum.langchain.com/t/clarification-on-how-pydantic-schema-descriptions-are-used-in-with-structured-output/1612/5 "2025-09-24T06:59:36Z")

</div>

Great! This adds further clarity! Thanks again 🙂
