langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Enable Log Probabilities When Using Structured Outputs in OpenAI Models

Open dbuos opened this issue 2 weeks ago • 2 comments

Discussed in https://github.com/langchain-ai/langchain/discussions/29665

Originally posted by dbuos February 7, 2025

Checked

  • [X] I searched existing ideas and did not find a similar one
  • [X] I added a very descriptive title
  • [X] I've clearly described the feature request and motivation for it

Feature request

Currently, LangChain does not provide a way to retrieve log probabilities (logprobs) when using OpenAI models with structured outputs. However, this feature is valuable for applications that require confidence estimates, uncertainty quantification, or probabilistic reasoning over generated tokens.

Expected Behavior: • When requesting structured outputs, allow the user to enable logprobs in OpenAI calls. • Expose token-wise log probabilities in the response for further analysis.

Proposed Solution: • Modify the OpenAI wrapper to allow logprobs when using structured outputs. • Ensure compatibility with existing response parsing mechanisms.

Motivation

Use Case: • Evaluating model confidence in structured generations. • Debugging and improving prompt engineering with probabilistic insights.

Proposal (If applicable)

•	Modify the OpenAI wrapper to allow logprobs when using structured outputs.
•	Ensure compatibility with existing response parsing mechanisms.</div>

dbuos avatar Feb 07 '25 15:02 dbuos