Catalog PyPI
Back to packageRELEASE DETAILS

0.2.1

PyPI

aidial-integration-langchain

Utilities for integration of AI DIAL API with Langchain library

Published9 Apr 2026
Direct dependencies12
Transitive dependenciesNot calculated

README

Version 0.2.1 documentation

Overview

PyPI version

The package provides helpers facilitating integration of DIAL API with Langchain library.

Passing DIAL-specific extra fields in Langchain requests/responses

Unlike openai library, langchain-openai library doesn't allow to pass extra request/response parameters to/from the upstream model.

The minimal example highlighting the issue could be found in the example folder:

cd example
python -m venv .venv
source .venv/bin/activate
pip install -q -r requirements.txt
python -m app
Received the following extra fields:
(1) ☑ request.extra_field
(2) ☑ request.tools[0].extra_field
(3) ☐ request.messages[0].extra_field
(4) ☐ response.message.extra_field
(5) ☐ response.extra_field

langchain-openai ignores certain extra fields, meaning that the upstream endpoint won't receive (2) and the client won't receive (4) and (5) if they were sent by the upstream.

Note that top-level request extra fields and tool definition extra fields do actually reach the upstream.

Solution

One way to fix the issue, is to modify the Langchain methods that ignore these extra fields so that they are taken into account.

This is achieved via monkey-patching certain private methods in langchain-openai that do the conversion from the Langchain datatypes to dictionaries and vice versa.

Usage

Install the aidial-integration-langchain package as a dependency in your project:

pip install aidial-integration-langchain

Then import aidial_integration_langchain before importing any Langchain module to apply the patches:

import aidial_integration_langchain.patch # isort:skip  # noqa: F401 # type: ignore

from langchain_openai import AzureChatOpenAI
...

The same example as above, but with the patch applied:

cd example
python -m venv .venv
source .venv/bin/activate
pip install -q -r requirements.txt
pip install -q aidial-integration-langchain
python -m app patch
Received the following extra fields:
(1) ☑ request.extra_field
(2) ☑ request.tools[0].extra_field
(3) ☑ request.messages[0].extra_field
(4) ☑ response.message.extra_field
(5) ☑ response.extra_field

Supported Langchain versions

The following langchain-openai versions have been tested for Python 3.9, 3.10, 3.11, 3.12, and 3.13:

VersionRequest per-messageResponse per-messageResponse top-level
>=0.1.1,<=0.1.22🟢🟢🔴
>=0.1.23,<=0.1.25🟢🟢🟢
>=0.2.0,<=0.2.14🟢🟢🟢
>=0.3.0,<=0.3.18🟢🟢🟢

[!NOTE] The patched langchain-openai<=0.1.22 doesn't support response top-level extra fields, since the structure of the code back then was not very amicable for monkey-patching in this particular respect.

Configuration

The list of extra fields that are allowed to pass-through is controlled by the following environment variables.

NameDefaultDescription
LC_EXTRA_REQUEST_MESSAGE_FIELDScustom_contentA comma-separated list of extra message fields allowed to pass-through in chat completion requests.
LC_EXTRA_RESPONSE_MESSAGE_FIELDScustom_contentA comma-separated list of extra message fields allowed to pass-through in chat completion responses.
LC_EXTRA_RESPONSE_FIELDSstatisticsA comma-separated list of extra fields allowed to pass-through on the top-level of the chat completion responses.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 12

Native requirements
12 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
langchain
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
langchain<2runtime
langchain-core
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
langchain-core<2runtime
langchain-openai
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
langchain-openai<0.4,>=0.1.1runtime
openai
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
openai<2,>=1.48runtime
flake8
Environment
{
  "extras": "",
  "marker": "extra == \"lint\"",
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
flake8>=6.0.0; extra == "lint"runtime
black
Environment
{
  "extras": "",
  "marker": "extra == \"lint\"",
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
black>=26.3.1; extra == "lint"runtime
isort
Environment
{
  "extras": "",
  "marker": "extra == \"lint\"",
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
isort>=5.12.0; extra == "lint"runtime
pyright
Environment
{
  "extras": "",
  "marker": "extra == \"lint\"",
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
pyright>=1.1.324; extra == "lint"runtime
autoflake
Environment
{
  "extras": "",
  "marker": "extra == \"lint\"",
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
autoflake>=2.2.0; extra == "lint"runtime
pytest
Environment
{
  "extras": "",
  "marker": "extra == \"test\"",
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
pytest>=7.4.2; extra == "test"runtime
pytest-asyncio
Environment
{
  "extras": "",
  "marker": "extra == \"test\"",
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
pytest-asyncio>=0.21.1; extra == "test"runtime
httpx
Environment
{
  "extras": "",
  "marker": "extra == \"test\"",
  "requires_python": "<4.0,>=3.10",
  "evaluation": "NOT_EVALUATED"
}
httpx==0.27.2; extra == "test"runtime

Distribution files

2 collected
aidial_integration_langchain-0.2.1-py3-none-any.whl

bdist_wheel · 5.3 KB · Python py3

Source file
aidial_integration_langchain-0.2.1.tar.gz

sdist · 4.17 KB · Python source

Source file

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 10:30 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:06b24a92e8ea3ead4e137178fdfa22bb1abe7e5c0b1c9db4589e68249bb42909

Other collected versions

View all collected versions →