Skip to main content
Set or clear additional context information on a language model instance. The context is attached to all spans created for this model and is stored as gen_ai.llm.context. Supports both BaseLanguageModel instances and RunnableBinding objects. Passing None removes the context so that subsequent spans no longer carry it. This is useful in multi-step agent workflows where context set after a RAG step should not leak into later non-RAG LLM calls.

Parameters

llm
BaseLanguageModel | RunnableBinding
required
The language model instance or binding.
context
str | None
default:"None"
The context string to attach, or None to clear.

Raises

TypeError – If a RunnableBinding is provided but its bound object is not a BaseLanguageModel.

Returns

None Example: default from langchain_openai import ChatOpenAI from fiddler_langgraph import set_llm_context llm = ChatOpenAI(model=“gpt-4”) set_llm_context(llm, “User prefers concise responses in Spanish”) # Clear context before non-RAG steps set_llm_context(llm, None)