> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fiddler.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# set_llm_context

> Set or clear additional context on a language model for inclusion in LLM spans.

Set or clear additional context on a language model for inclusion in LLM spans.

The context is stored in the model's metadata and read by
[`FiddlerAgentMiddleware`](/sdk-api/langchain/fiddler-agent-middleware) when
creating LLM spans. Supports both plain model instances and
`RunnableBinding`.

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

<ParamField path="llm" type="BaseLanguageModel | RunnableBinding" required={true}>
  The language model (or binding) to attach context to.
</ParamField>

<ParamField path="context" type="str | None" required={false} default="None">
  The context string to attach, or `None` to clear.
</ParamField>

## Raises

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

## Returns

<ResponseField>
  None Example: default from langchain\_openai import ChatOpenAI from fiddler\_langchain import set\_llm\_context llm = ChatOpenAI(model="gpt-4o") set\_llm\_context(llm, "User prefers concise responses") # Clear context before non-RAG steps set\_llm\_context(llm, None)
</ResponseField>
