Skip to main content
Remove LLM context from a language model instance. This is a convenience wrapper that calls set_llm_context(llm, None). Use it in multi-step agent workflows after a RAG retrieval step to ensure subsequent non-RAG LLM calls (tool planning, routing, etc.) do not carry stale context and do not trigger faithfulness evaluation. The context is stored in the model’s metadata and read by FiddlerAgentMiddleware when creating LLM spans.

Parameters

llm
BaseLanguageModel | RunnableBinding
required
The language model instance or binding to clear context from.

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_langchain import set_llm_context, clear_llm_context llm = ChatOpenAI(model=“gpt-4o”) retrieved_context = “Relevant documents joined as a single string…” rag_prompt = “Answer the question using the context above.” planning_prompt = “Plan the next agent step.” # Step 1: RAG retrieval — attach context for faithfulness evaluation set_llm_context(llm, retrieved_context) response = llm.invoke(rag_prompt) # faithfulness evaluated # Step 2: Non-RAG planning — clear context to skip faithfulness evaluation clear_llm_context(llm) plan = llm.invoke(planning_prompt) # no faithfulness evaluation

SEE ALSO

set_llm_context() – Set or clear context on a language model instance. Passing None as the context value is equivalent to calling clear_llm_context().