Laya Python Guide: Choice, Score & Noul

Learn the Laya Python API for choice, score, and noul typed decisions with practical examples, Router usage, confidence guidance, and production patterns.

Last updated: Sep 22, 2026

Laya's Python API centers on a state plus a dictionary of typed questions.

Install first:

pip install laya

Then create a Router:

from laya import Router

router = Router(preload=True)

choice

Use choice when one option should be selected from named criteria.

questions = {
    "department": {
        "type": "choice",
        "instructions": "Which team should handle this ticket?",
        "criteria": {
            "billing": "payments, invoices, refunds",
            "technical": "bugs, outages, errors",
            "sales": "pricing and contracts"
        }
    }
}

Keep option descriptions distinct. The upstream project documents degradation when a single choice contains very large label sets at default settings.

score

Use score for an ordered rubric.

questions = {
    "urgency": {
        "type": "score",
        "instructions": "How urgent is this request?",
        "criteria": [
            "not urgent",
            "needs attention soon",
            "critical or blocking"
        ]
    }
}

A score is not the same thing as a free-form rating explanation. The application receives a structured ordinal result.

noul

Use noul when the question is a proposition.

questions = {
    "churn_risk": {
        "type": "noul",
        "instructions": "Does the user threaten to cancel or leave?"
    }
}

The output includes a probability. Do not automatically treat an upstream confidence threshold as correct for your domain; calibrate and validate with your own data.

Multiple questions in one call

One of Laya's core design goals is evaluating multiple typed questions in one forward pass.

result = router.predict(state, {
    **department_question,
    **urgency_question,
    **churn_question,
})

Production pattern

A practical production system often looks like:

  1. Laya evaluates the decision.
  2. High-confidence, validated cases follow an automated path.
  3. Ambiguous cases fall back to a larger model or human review.
  4. Outcomes are logged so thresholds can be re-evaluated.

The exact threshold should come from your data rather than a copied example.

For a complete walkthrough on a real task, from the first call to thresholds and evaluation, see How to use Laya.

Source: upstream Laya repository.

Last verified: September 22, 2026.