Mobile Betting · 16 / 26

LangSmith Example

The mobile betting platform built with LangGraph and traced, tested and monitored in LangSmith: graph, tracing, datasets and release gates.

The same platform with LangGraph and LangSmith

LangGraph models KYC handling as a graph of nodes with explicit state, and LangSmith traces every run, stores datasets and runs evaluations. This build suits teams that want code-level control and a tight test loop. It uses the same tool contracts, gateway and security profile as the other builds.

NodeKindWhat it does
ingestCodeReads the application, stores document pointers, tokenises identity data
extractModel (fast)Extracts name, date of birth, number and expiry into a validated schema
checkCode and providersRuns age, location and sanctions checks through the rules and providers
decideCodeChooses the basis: every rule passes, or an analyst
reviewHuman in the loopPauses until an analyst approves or rejects
applyToolOpens the account with limits prompt, with a basis and idempotency key
rejectToolRecords the decision and the reason
notifyToolSends a short note from an approved template

The graph in code

State is a typed object. The decide node routes by basis, and the review node interrupts the run and resumes only when an analyst answers, so there is no path to approve a case that failed or did not complete a check without a person. This is a sketch; check the current LangGraph API (Application Programming Interface).

agent/kyc_graph.py · only a clean rule result or an analyst can reach apply
from typing import TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.postgres import PostgresSaver
from langgraph.types import interrupt, Command

class KycCase(TypedDict, total=False):
    application: dict
    fields: dict
    checks: dict            # age, location, sanctions from the rules and providers
    decision: dict
    approved_by: str

def review(state: KycCase) -> Command:
    answer = interrupt({"case": state["application"]["case_id"], "checks": state["checks"], "fields": state["fields"]})   # pauses here
    return Command(update={"approved_by": answer["analyst"], "decision": answer["decision"]},
                   goto="apply" if answer["decision"]["action"] == "approve" else "reject")

g = StateGraph(KycCase)
for name, fn in [("ingest", ingest), ("extract", extract), ("check", run_checks), ("decide", decide),
                 ("review", review), ("apply", apply_decision), ("reject", reject), ("notify", notify)]:
    g.add_node(name, fn)
g.add_edge(START, "ingest")
g.add_edge("ingest", "extract")
g.add_edge("extract", "check")
g.add_edge("check", "decide")
g.add_conditional_edges("decide", route_by_basis, ["apply", "review"])   # every rule passes, else an analyst
g.add_edge("apply", "notify")
g.add_edge("reject", "notify")
g.add_edge("notify", END)

app = g.compile(checkpointer=PostgresSaver.from_conn_string(DB_URL))
Pause for review, resume on the analyst's answer The graph runs to the decide node, finds a name mismatch, saves its state and pauses at review. The analyst's choice arrives later as a new request, the service resumes the thread from the saved state, and only then does the graph apply. Spans go to LangSmith. KYC analyst Service API LangGraph app Checkpointer Platform tools LangSmith invoke, thread id extract, check, decide save state at review interrupt: wait paused, mismatch summary review task approve: spelling variant resume, thread id load saved state apply decision, basis analyst + key account opened trace spans done
Pause for review, resume on the analyst's answer

State survives the pause, so an analyst can answer in a minute or an hour, and a restart of the service does not lose the case.

Tracing every unit of work

LangSmith traces each run with nested spans for model calls, tools and retrieval. Metadata ties a trace to a case, a stage and the gateway's trace identifier, so a wrong decision can be followed from the document to the scan and the account change.

service configuration · masking before traces leave your network
# Environment for the service
LANGSMITH_TRACING=true
LANGSMITH_PROJECT=betting-prod
LANGSMITH_HIDE_INPUTS=true      # keep documents, identity and gambling data out of the tracing vendor
LANGSMITH_HIDE_OUTPUTS=true     # trace a redacted copy instead

# In code: attach the identifiers and a redacted view
result = app.invoke(
    {"application": application},
    config={"configurable": {"thread_id": application["case_id"]},
            "metadata": {"stage": "kyc", "gateway_trace_id": trace_id, "jurisdiction": jurisdiction},
            "tags": ["prod"]},
)

Raw inputs and outputs are hidden by default, and a redaction step writes a masked copy of the fields needed to debug: check results, rule identifiers, bases and outcomes, without identity, location or gambling detail. This follows ADR-006.

Datasets and evaluation

A dataset holds cases with the expected outcome: the checks, the basis, and whether the case should go to a person. Offline runs compare the graph against the dataset on every change, and message checks guard against any text that urges play.

tests/test_eval.py · offline evaluation as a release gate
from langsmith import Client, evaluate

client = Client()

def decided_by_rule_or_analyst(run, example) -> dict:
    ok = run.outputs["decision"]["basis"] in ("rule_clear", "analyst_approved")
    return {"key": "decided_by_rule_or_analyst", "score": 1.0 if ok else 0.0}

def no_urging_in_message(run, example) -> dict:
    text = (run.outputs.get("message") or "").lower()
    banned = ("bet now", "don't miss", "free bet", "double your", "win back")
    return {"key": "no_urging_in_message", "score": 0.0 if any(b in text for b in banned) else 1.0}

results = evaluate(
    run_kyc_case,                                    # target: runs the graph on one example
    data="mb-eval-v8",
    evaluators=[decided_by_rule_or_analyst, no_urging_in_message, extraction_f1, groundedness_judge],
    experiment_prefix="pr-4120",
    max_concurrency=4,
)
A LangSmith offline experiment CI calls evaluate with the target and a dataset. The client loads the examples, runs the graph on each, scores the outputs with the evaluators and stores an experiment, then CI compares it with the baseline and passes or fails the check. CI LangSmith client Dataset Graph under test Evaluators Experiment evaluate(target, data) load mb-eval-v8 examples run each example outputs, tool calls score outputs scores store experiment results vs baseline gate: pass or fail
A LangSmith offline experiment

Every example runs in its own trace, so a failing score links straight to the case that caused it.

Release gates and online monitoring

CheckHowThreshold
ID (identifier) extraction accuracyF1 against labelled documentsAt least 0.97
Eligibility decided only by rules or an analystCode evaluator on the dataset and on production tracesExactly 1.0, any failure blocks release
No message urges playCode evaluator and a judge on draftsExactly 1.0
Cases that need a person do go to oneDataset of mismatches, forgeries and adversarial casesAt least 98%
Rule answer groundednessJudge model, spot-checked by peopleAt least 0.9
Cost per KYC documentToken and cost metadata on tracesWithin 10% of the last release
Drift in productionOnline evaluators on sampled traces, with alertsAlert on a drop of 5 points

The improvement loop

  1. Sample

    Online evaluators and analyst corrections flag cases for review.

  2. Review

    An annotation queue puts flagged traces in front of a compliance lead, who marks what should have happened.

  3. Add to the dataset

    Reviewed traces become new dataset examples, after redaction.

  4. Fix and compare

    Change the prompt, rule or tool, run the experiment and compare against the baseline on the same dataset.

  5. Release

    The gate passes, the new version is promoted and the online evaluators watch the result.

Build this for your business

This example is a player protection and operations platform for a licensed betting operator, but the same pattern, deterministic rules for every hard duty, a governed gateway, runtime security, protect-first automation and measured quality, fits any regulated, customer-facing service. We can scope a pilot on your own systems.

Book a discovery call