What's the right langchain API for binding output parsing vs native structured generation vs tool calling. (Target models - GPT4o & Gemini 1.5 pro) #6851
Unanswered
AnishPimpley
asked this question in
Q&A
Replies: 1 comment
-
To ensure you're using native structured outputs for Azure ChatOpenAI (GPT 4o latest) and ChatVertexAI (Gemini 1.5 pro), you can use the
These examples ensure that the output adheres to the defined schema, providing structured data generation for your use case with Azure ChatOpenAI and ChatVertexAI [1][2]. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checked other resources
Commit to Help
Example Code
Description
My usecase:
To generate long form text (blogs) with structed output generation. The current structured generation workflow in langchain has ~4 ways of generating structured output. I am confused about which is which.
I'm outlining all the types of structured text generation in langchain below. They are in order of preference.
This is where the LLM provider takes care of structured output generation. The LLM provider ingests a pydantic schema and guarantees structured output. The provider's implementation is opaque, but the intuition is that the LLM provider does "normal generation + constrained decoding" on their servers. There may be some extra tuning or prompt engineering work done on their end, but it is black-box. This is most desirable, as the implementation is native with minimal langchain interference.
The precursor to structured outputs. It guarantees JSON but doesn't take in schema as parameter. Schema must be passed as part of the prompt. It is also natively supported by the LLM provider. Likely also uses "normal generation + constrained decoding". Must be paired with a 3rd party (langchain) output parser to guarantee that the JSON follows some target pydantic schema.
This is full YOLO mode. The model generates text. No guarantees for it to be valid JSON or follow a schema. But, most times the model still succeeds. All guarantees are relegated to the post processing output parser. This is not ideal, but is still better than function calling
Tool calling has the same handshake, but llm providers use a separate fine tuned models (openai functions) for tool calling. Tool calling finetunes make the models concise, and unsuitable for long form text generation. I do not want tool calling, it creates tiny outputs and is strongly biased to write like a programmer, not a creative individual.
My question:
I want to ensure I'm using native structured outputs for Azure ChatOpenAI (GPT 4o latest) and ChatVertexAI (gemini 1.5 pro).
What is the right python syntax for it ?
Is this the right syntax - https://python.langchain.com/docs/how_to/structured_output/#pydantic-class ?
System Info
platform - Linux (wsl)
package - python
Beta Was this translation helpful? Give feedback.
All reactions