Skip to content

langchain tool for yes no decisions

github-actions[bot] edited this page Oct 5, 2026 · 5 revisions

A LangChain tool for local yes/no decisions

You can give a LangChain agent local yes/no decisions by wrapping one HTTP call to jev serve in a function and decorating it with @tool, but for checks that must always run, call the same function directly in your code instead of letting the agent decide whether to use it. A tool is something the chat model chooses to call; a guardrail, a routing decision or a stop condition should not depend on that choice. The function is the same in both cases: text and question in, P(yes) out, no text generated by the local model and nothing to parse.

That split is the real design decision on this page. LangChain makes it easy to hand a model a list of tools, and it is tempting to hand it every capability that way. For a decision you already know you want on every step, a plain function call is deterministic: it runs, you get a number, your code compares it with a threshold.

This page is the plain function, the tool wrapper and its description, the deterministic pattern, and what to watch for. The code is a minimal sketch to adapt; LangChain facts are from its documentation, fetched 2026-09-29, and only the documented jev API is used.

The plain function first

import requests

JEV = "http://127.0.0.1:8017/v1/systemone"
session = requests.Session()

def p_yes(text: str, question: str) -> float:
    body = {"model": "jev-latest", "state": text,
            "questions": {"q": {"type": "noul", "instructions": question}}}
    r = session.post(JEV, json=body, timeout=(3.05, 10))
    r.raise_for_status()
    return r.json()["answers"]["q"]["noul"]

This is all the integration needs. If you have several questions about the same text, send them in one request with one key each: the text is read once, and on the reference laptop three questions take about 66 ms together against 49 ms for one alone. Timeouts, retries and error handling for this call are on a Python client for local LLM decisions.

The tool wrapper

LangChain's docs define a tool with the @tool decorator from langchain.tools. Two rules from those docs shape the wrapper: "the function's docstring becomes the tool's description that helps the model understand when to use it", and "type hints are required as they define the tool's input schema".

from langchain.tools import tool

@tool
def text_says(text: str, question: str) -> str:
    """Probability (0 to 1) that the answer to a yes/no question about the given text is yes.
    Use it to check what a text states. The question must be in English, ask one thing,
    and be answerable from the text alone. It cannot do arithmetic or look anything up."""
    return f"{p_yes(text, question):.2f}"

The tool is passed to an agent the way the docs show, create_agent(model, tools=[...]). The docstring is doing real work here: it is the only thing the chat model knows about the tool, so it states the limits. A large model that thinks the tool can check a sum will ask it to, and a small local model is weak at exactly that: on the fraud-points task, where a score is added up from six rules, jevos-v4 got 0.50 right against 0.69 for the hosted Jev.

The deterministic pattern: call it in the chain

Most useful local decisions are not things an agent should opt into. They are fixed points in your pipeline:

draft = generate_reply(ticket)                      # your LLM step
if p_yes(draft, "Does the reply promise the customer a refund?") > 0.5:
    send_to_human(ticket, draft)                    # never auto-send a refund promise
else:
    send(draft)

The check runs on every draft, costs no tokens on the paid model, takes a fraction of a second locally, and its threshold is in your code where a reviewer can see it. The same shape covers the patterns on gating AI agent tool calls with yes/no checks (before a refund or delete tool runs) and stop conditions for AI agents ("is the task complete?"). A router that sends only doubtful cases to a large model is on a model cascade: small model first, large model on doubt.

Tool or function: how to choose

Situation Use
The check must run every time (safety, policy, routing) plain function in the chain
The agent may need to verify a fact in a document it is reading tool
The result decides who sees an output plain function, plus a human band
You want the agent to explore what a long text says tool, with one question per call

A tool call also puts the local model's answer into the chat model's context as text, where it becomes one more thing the large model may reinterpret. When your code reads the float directly, the number means exactly what it says.

When a LangChain tool is the wrong wrapper

  • jevos answers yes/no, multiple-choice and (early) score questions in English and nothing else. It is not a chat model and cannot be used as the agent's main model in LangChain.
  • The probability is only as good as the question. Questions the model has to compute, dates and sums, lean toward yes; that measurement was taken on the first jevos and is on why a small LLM says yes when the answer is no.
  • A yes/no check is a filter, not a security boundary. An agent that can call dangerous tools needs permissions in the tools themselves, with the check as one layer on top.

Short answers to the questions that lead here

Is there a LangChain integration package for jevos? No. A decorated function around one HTTP call is all it takes.

Can I use jevos as the LLM in a LangChain agent? No. It generates no text; it only returns probabilities for yes/no, choice and score questions.

Why return a string from the tool? The docs' examples return strings, and the chat model reads the result as text. In your own code, use the float from the plain function.

Is the tool deterministic? The call and your threshold are. Whether an agent calls the tool is up to the chat model, which is why fixed checks belong in code.

How fast is one call? About 28 ms for a short request and 130 ms for a long one on an Intel Core Ultra 7 255H with 16 threads.

See also: AI agent guardrails with yes/no questions, replacing chat LLM calls with yes/no questions and reducing LLM cost with local yes/no decisions.

Sources

  • Request shape and endpoint: the jev README. Latencies: the README, measured with jevos-v3, which has the same size and speed as jevos-v4. Accuracy: the README's six-task table for jevos-v4.
  • LangChain tools: the @tool decorator, docstrings as descriptions, type hints as schema, and create_agent(model, tools=[...]), fetched 2026-09-29.

From the notes of jev, a yes/no decision model that runs on a laptop CPU. The best place for a check you always want is a line of code, not a tool on a menu.

Guides

Measurements

Comparisons

Speed

Probability and thresholds

Question design

Use cases

Evaluation

Agents and routing

Integrations

Local and private AI

llama.cpp and GGUF

Clone this wiki locally