Skip to content
Bits & Flames Fyron Documentation GitHub
DocsDecision models (System 1)

Direct classification and decision models

Use a direct classifier when you can define the question, the evidence and the allowed answers before a run. Here System 1 means a workflow that makes one model call per document for a fixed question. The term describes how you use the model. It makes no promise about the model’s internal reasoning or response time.

Available inputDecision to makeFyron route
Report textDoes this report explicitly recommend follow-up?Apply one named prompt and validate its returned label, as below.
A probability from a fitted classifierDoes the score cross the study’s chosen threshold?Apply a locked threshold and evaluate against held-out labels.
Evidence that must be discovered firstWhich document should I read to answer this question?Use the agent harness to select tools over several turns.

Assign one research label per document

Start with an approved text endpoint configured as in the LLM setup guide. This example captures what was documented. An unclear or silent note goes to review.

python
import pandas as pd
from fyron.llm import LLMAgent

agent = LLMAgent()
notes = pd.DataFrame([
    ("A", "Repeat imaging in six weeks."),
    ("B", "No follow-up imaging is recommended."),
    ("C", "Comparison with prior study."),
], columns=["doc_id", "text"])

pack = [{"name": "follow_up_label", "prompt": (
    "Classify the documented imaging follow-up recommendation. Return exactly one label. "
    "recommended: the text explicitly recommends follow-up imaging. "
    "not_recommended: the text explicitly advises against follow-up imaging. "
    "unclear: the text is silent, ambiguous or contradictory."
)}]
results = agent.run_prompts_on_dataframe(
    notes, text_col="text", document_id_col="doc_id", keep_cols=["doc_id"], prompts=pack,
)
allowed = {"recommended", "not_recommended", "unclear"}
candidate = results["answer"].astype("string").str.strip()
valid = results["status"].eq("ok") & candidate.isin(allowed)
results["label"] = candidate.where(valid)
results["needs_review"] = ~valid | results["label"].eq("unclear")
print(results[["doc_id", "status", "reason", "answer", "label", "needs_review"]])

A, B and C illustrate the intended labels in order. The adapter returns text, so the Python check enforces the vocabulary. An explanation such as “probably recommended” remains available in answer and goes to review. A failed request also goes to review with its original status and reason. If you already have an endpoint serving a direct decision model, it can be used here when its input and output match a supported LLMAgent adapter. A custom text endpoint must accept Fyron’s text and model fields and return a JSON object with a text answer.

Apply a decision threshold to classifier probabilities

If your model already returns numeric probabilities, use the ML and validation APIs directly. Install the ml and validation extras. The synthetic numbers below represent probabilities of the positive class from a fitted model and independent reference labels. Use patient-disjoint validation and test sets.

python
from fyron.validation import find_best_threshold
from fyron.ml import evaluate_locked_threshold

choice = find_best_threshold(
    y_true=[0, 1, 0, 1], y_prob=[0.10, 0.60, 0.40, 0.85],
    thresholds=[0.3, 0.5, 0.7], metric="balanced_accuracy",
)
test = evaluate_locked_threshold(
    y_true=[1, 0, 1, 0], y_prob=[0.80, 0.15, 0.45, 0.25],
    threshold=choice["threshold"],
)
print(test["threshold"], test["sensitivity"], test["specificity"])

Validation selects 0.5. On the four held-out examples, one of the two positives crosses that threshold and both negatives fall below it. For text labels, compare predictions to reviewed labels and report review coverage alongside performance. Use probability-based metrics only when your model produces appropriate numeric scores. A confidence percentage written by an LLM needs independent calibration before it can be interpreted as a probability. Classification workflows · Model validation