GoogleGenAIClassifier exposes these decisions as a LangChain Runnable, so you can invoke, batch, or compose them with other runnables. It accepts strings, JSON objects and arrays, LangChain message objects, and standard media blocks, and records traces and token usage in LangSmith. You can also use it with agent middleware to route models and gate tool calls. Use it for focused decisions such as routing a request, flagging content for review, or rating severity, where application code acts on the probability or confidence.
GoogleGenAIClassifier is in beta and requires langchain-google-genai>=4.5.0 and google-genai>=3.2.0. Its API may change without notice.Setup
GoogleGenAIClassifier reads GOOGLE_API_KEY, then GEMINI_API_KEY. Requests always use the Gemini Developer API, not Gemini Enterprise Agent Platform.
Quickstart
Create aGoogleGenAIClassifier with a decisions model, then pass the state and named questions together in each invocation. Questions that share state are answered in one request:
nouls, choices, and scores. All answers are also available on answers. The response carries the model that answered and token usage.
The question and response types, such as Noul and ClassifierResponse, come from langchain_core.decisions.
Every question requires instructions. Write the full question there, even when its name looks self-explanatory.
Question types
Each question is one of three types:Noul: Returns a probability between0.01and0.99, so a threshold above0.99never matches. A value near0.5means uncertainty, not “medium”, so useScorefor a spectrum. Passcriteriawithtrueandfalsedescriptions when the instructions alone leave room for interpretation.Noulanswers have noconfidence, because the probability is the answer.Choice: Maps each label to a description, or toNonewhen the label needs no description. Include anotherlabel when your options may not cover every input.confidenceis the probability of the selected label.Score: Takes two or more levels, ordered from lowest to highest and indexed from0. The returnedscoreis the probability-weighted average of the level indices, so it may fall between levels, andlegendmaps each index to its description.confidenceis the probability of the selected level.
ValueError.
langchain_core.decisions also defines a Box question type for locating objects in images. The Gemini Decisions API does not support it, and GoogleGenAIClassifier raises ValueError for a request that includes one.
State
Thestate can be a string, a JSON object or array, or LangChain messages at any depth inside an object or array:
- Strings: Sent as-is.
- JSON objects and arrays: Sent as JSON text.
- LangChain messages: Converted to role and content objects, then sent as JSON text.
- Media blocks: Standard
image,audio,video, andfileblocks withbase64orurldata are sent as native media, at the position where they appear in the JSON text. Blocks with other data sources raiseValueError.
Configuration
Errors
ValueError: Raised when no API key is available and noclientis supplied, when a request includes aBoxquestion, or when question instructions or criteria contain a media block.ModelRefusalError: Raised when the API blocks the input. The message includes the block reason. Import it fromlangchain_core.exceptions.
Agent middleware
LangChain includes two beta middleware that use a decision model at an agent’s decision points. Pass aGoogleGenAIClassifier as their classifier. Both require langchain>=1.5.0:
Route models
ModelRouterMiddleware picks one of your named models for each agent run, based on the latest human message:
Gate tool calls
AutoModeMiddleware checks each call to the tools you list, and blocks calls the classifier judges risky:
delete_file, the middleware returns an error ToolMessage instead of running the tool, and the agent reports that the call was blocked.
Tracing
GoogleGenAIClassifier runs are traced in LangSmith with the google_genai provider and model name, so you can inspect decisions and token usage alongside the rest of your application.
See also
- Gemini Decisions API guide
- Google provider overview
- ChatGoogleGenerativeAI
- Prebuilt middleware
- OpenAI Decisions integration
- LangChain Google GenAI API reference
Connect these docs to your agent of choice via MCP for real-time answers.

