Python API Reference¶
Top-level exports¶
clickproof
¶
clickproof - persistent GUI behavioral facts for computer-use agents.
DecayProjection(fact_id, element, current_score, score_in_7_days, score_in_30_days, days_until_threshold, recommendation)
dataclass
¶
Decay projection for a single UIFact.
Attributes:
| Name | Type | Description |
|---|---|---|
fact_id |
str
|
ID of the UIFact. |
element |
str
|
Semantic element description. |
current_score |
float
|
Score right now. |
score_in_7_days |
float
|
Projected score 7 days from now. |
score_in_30_days |
float
|
Projected score 30 days from now. |
days_until_threshold |
float
|
Days until score drops below min_score (0.0 if already below threshold or if it can never reach threshold). |
recommendation |
str
|
One of |
ClickAttempt(fact_id, target_element, hit, force_used=False, overlay_intercepted=False, observed_effect=True, agent_run_id='', notes='')
dataclass
¶
One computer-use click against a stored UIFact.
Farm OVERLAY-CLICK: Playwright force=True can hit an overlay
(e.g. X #layers) and never throw - the agent thinks it clicked the
target. Callers must report whether the intended element was hit.
is_miss
property
¶
True when the intended target did not receive a real click.
ClickOutcomeResult(ok, invalidated, miss_kind, score_before, score_after, confidence_after, observation_confirmed, fact_id, reason)
dataclass
¶
Result of recording a click attempt against a fact.
ClosedLoopError
¶
Bases: ValueError
Raised when the gate refuses empty or unusable fact stores.
GateOutcome(ok, verdict, reason, exit_code, fact_count=0, usable_count=0, stale_count=0, min_score_seen=None, human_required=False, action=None, task=None, risk=None)
dataclass
¶
Result of a closed-loop read of a clickproof fact store or task gate.
Attributes:
| Name | Type | Description |
|---|---|---|
ok |
bool
|
True only when a pipeline may continue (PASS). |
verdict |
str
|
|
reason |
str
|
Human-readable explanation (always non-empty). |
exit_code |
int
|
0 PASS, 1 FAIL (stale/low-confidence), 2 FAIL_LOUD (empty). |
fact_count |
int
|
Number of facts examined. |
usable_count |
int
|
Facts with score >= min_score. |
stale_count |
int
|
Facts with score < min_score. |
min_score_seen |
float | None
|
Lowest score among facts (None if empty). |
human_required |
bool
|
True when adversarial/out-of-scope needs human review. |
action |
str | None
|
Proposed action when task-alignment gated. |
task |
str | None
|
Declared task when task-alignment gated. |
risk |
str | None
|
|
to_dict()
¶
Serialise for JSON reports (eagle-eyes dogfood, CI artifacts).
Source code in clickproof/closed_loop.py
SessionMemory(session_id, app_name, app_version, loaded_fact_ids, bootstrap_text, loaded_at, usable_count, min_score)
dataclass
¶
Facts loaded for one computer-use agent session.
GUI-MEMORY: sessions that skip load while the store already holds usable facts for the app re-discover the UI every run - the farm failure mode.
ContextDecision(decision_id, choice, sparse_context=dict(), dominant_cues=dict(), attended_keys=(), choice_by_context=dict())
dataclass
¶
One multimodal / GUI decision with context inventory.
Attributes:
| Name | Type | Description |
|---|---|---|
decision_id |
str
|
Stable id for the choice. |
choice |
str
|
Selected option label (e.g. creative id, button path). |
sparse_context |
dict[str, Any]
|
Sparse decision-critical vars (market, locale, …). |
dominant_cues |
dict[str, Any]
|
High-volume product/visual signals. |
attended_keys |
tuple[str, ...]
|
Context keys the model claims to have used. |
choice_by_context |
Mapping[str, str]
|
Optional map context fingerprint → choice (for cross-context collapse detection across a batch). |
CVEReport(sparse_keys_present, sparse_keys_missing, attended_sparse, ignored_sparse, dominant_only, cross_context_collapse, collapsed_contexts)
dataclass
¶
Analysis of contextual variable overestimation risk.
FactObservation(fact_id, observed_at, confirmed, agent_run_id='')
dataclass
¶
An observation that confirms or refutes a UIFact.
Attributes:
| Name | Type | Description |
|---|---|---|
fact_id |
str
|
ID of the UIFact this observation pertains to. |
observed_at |
float
|
Unix timestamp when this observation was made. |
confirmed |
bool
|
True = fact still holds; False = fact no longer holds. |
agent_run_id |
str
|
Optional tracing identifier. |
id |
str
|
Content-addressed identifier - SHA-256[:16] of "{fact_id}|{observed_at}|{confirmed}". |
UIFact(app_name, app_version, element, action, outcome, context='', confidence=1.0, recorded_at=time.time())
dataclass
¶
A behavioral fact about a UI element in a specific app version.
UIFacts are the atoms of clickproof. Two UIFacts with the same app_name, app_version, element, and action always have the same ID.
Attributes:
| Name | Type | Description |
|---|---|---|
app_name |
str
|
Application identifier, e.g. "salesforce", "gmail". |
app_version |
str
|
Version string, e.g. "2025.11", "unknown". |
element |
str
|
Semantic element description, e.g. "export-csv-button". |
action |
str
|
What to do: "click", "type", "navigate". |
outcome |
str
|
What happens: "opens-download-dialog", "error:not-found". |
context |
str
|
Optional UI context, e.g. "reports-page". |
confidence |
float
|
Initial confidence in [0.0, 1.0]. Default 1.0. |
recorded_at |
float
|
Unix timestamp when this fact was recorded. |
id |
str
|
Content-addressed identifier - SHA-256[:16] of "{app_name}|{app_version}|{element}|{action}". |
to_dict()
¶
Serialize to a JSON-compatible dict.
Source code in clickproof/fact.py
from_dict(d)
classmethod
¶
Deserialize from a dict produced by to_dict().
Source code in clickproof/fact.py
FactRetriever(store, scorer=None)
¶
Retrieves and ranks relevant UIFacts for an agent session start.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
FactStore
|
The FactStore to query. |
required |
scorer
|
FactScorer | None
|
Optional FactScorer; a default one is created if not provided. |
None
|
Source code in clickproof/retriever.py
query(app_name, app_version=None, element=None, min_score=0.5)
¶
Return (fact, score) pairs sorted by score descending.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Required - filter by application name. |
required |
app_version
|
str | None
|
Optional - filter to a specific version. |
None
|
element
|
str | None
|
Optional - filter to a specific element (substring match). |
None
|
min_score
|
float
|
Minimum score threshold; facts below this are excluded. |
0.5
|
Source code in clickproof/retriever.py
bootstrap_context(app_name, app_version='unknown')
¶
Return a text summary of known facts for agent context injection.
The returned string can be prepended to an agent's system prompt to give it a snapshot of what is known about the target application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Application to summarize. |
required |
app_version
|
str
|
Optional version to scope the summary. |
'unknown'
|
Source code in clickproof/retriever.py
FactScore(fact_id, app_name, app_version, element, score, observation_count, confirmed_count, last_observed, staleness_days)
dataclass
¶
Confidence score for a UIFact given its observation history.
Attributes:
| Name | Type | Description |
|---|---|---|
fact_id |
str
|
ID of the scored UIFact. |
app_name |
str
|
Application identifier. |
app_version |
str
|
Version string. |
element |
str
|
Semantic element description. |
score |
float
|
Current confidence in [0.0, 1.0]. |
observation_count |
int
|
Total number of observations. |
confirmed_count |
int
|
Number of confirming observations. |
last_observed |
float
|
Unix timestamp of the most recent observation. |
staleness_days |
float
|
Days since the last observation. |
last_seen_at
property
¶
Alias for last_observed - provided for backward compatibility.
to_dict()
¶
Serialize to a JSON-compatible dict.
Source code in clickproof/scorer.py
FactScorer
¶
Computes confidence scores from observation history.
Algorithm
- Base: ratio of confirmed / total observations (uses initial confidence if no obs).
- Decay: multiply by staleness factor: e^(-0.1 * staleness_days).
- Boost: scale up with observation count (more observations = more confident). Final score = base_ratio * staleness_decay * _count_boost(count)
score(fact, observations)
¶
Compute a FactScore for a single UIFact given its observations.
Source code in clickproof/scorer.py
batch_score(facts, store)
¶
Score all facts using observations from the store.
Source code in clickproof/scorer.py
FactStore(path)
¶
SQLite-backed store for UIFacts and observations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to the SQLite database file. Use ":memory:" for an in-memory database (useful for testing). |
required |
Source code in clickproof/store.py
add_fact(fact)
¶
Insert a UIFact. Silently ignores duplicates (same id).
Source code in clickproof/store.py
get_fact(fact_id)
¶
Return a UIFact by id, or None if not found.
set_confidence(fact_id, confidence)
¶
Update stored confidence for a fact (OVERLAY-CLICK decay / invalidate).
Returns True if a row was updated. Confidence is clamped to [0.0, 1.0].
Source code in clickproof/store.py
list_facts(app_name=None, app_version=None)
¶
Return all UIFacts, optionally filtered by app_name and/or app_version.
Source code in clickproof/store.py
add_observation(obs)
¶
Insert a FactObservation. Silently ignores duplicates (same id).
Source code in clickproof/store.py
get_observations(fact_id)
¶
Return all observations for a given fact_id, ordered by observed_at.
Source code in clickproof/store.py
project_decay(store, scorer, app_name, min_score=0.5)
¶
Return decay projections for all facts belonging to app_name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
FactStore
|
An open FactStore to read from. |
required |
scorer
|
FactScorer
|
A FactScorer used to compute the current score. |
required |
app_name
|
str
|
Application name to project for. |
required |
min_score
|
float
|
Threshold below which a fact is considered stale. |
0.5
|
Returns:
| Type | Description |
|---|---|
list[DecayProjection]
|
List of :class: |
Source code in clickproof/analytics.py
stale_facts(store, scorer, app_name, min_score=0.5)
¶
Return facts whose current score is below min_score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
FactStore
|
An open FactStore to read from. |
required |
scorer
|
FactScorer
|
A FactScorer used to compute the current score. |
required |
app_name
|
str
|
Application name to filter by. |
required |
min_score
|
float
|
Score threshold; facts with score strictly below this are returned. |
0.5
|
Returns:
| Type | Description |
|---|---|
list[UIFact]
|
List of :class: |
Source code in clickproof/analytics.py
export_bootstrap_pack(store, app_name)
¶
Export a 'bootstrap pack' - minimal JSON with top-scored facts for an app.
Only facts with a score >= 0.5 are included, sorted by score descending, capped at the top 20.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
FactStore
|
An open FactStore to read from. |
required |
app_name
|
str
|
Application whose facts to export. |
required |
Returns:
| Type | Description |
|---|---|
str
|
JSON string with keys |
str
|
|
Source code in clickproof/bulk.py
export_facts(store, app_name=None)
¶
Export facts and observations as JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
FactStore
|
An open FactStore to read from. |
required |
app_name
|
str | None
|
If given, only export facts for this application. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
JSON string with keys |
Source code in clickproof/bulk.py
import_facts(store, json_str, merge_strategy='upsert')
¶
Import facts from JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
FactStore
|
An open FactStore to write into. |
required |
json_str
|
str
|
JSON string produced by :func: |
required |
merge_strategy
|
str
|
One of |
'upsert'
|
Returns:
| Type | Description |
|---|---|
int
|
Number of facts imported (observations are always imported alongside). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If merge_strategy is not a recognised value. |
Source code in clickproof/bulk.py
apply_click_outcome(store, attempt, *, scorer=None, miss_confidence_factor=0.25, invalidate_confidence=0.05)
¶
Record click result: confirm on hit, refute + decay confidence on miss.
Returns:
| Type | Description |
|---|---|
ClickOutcomeResult
|
class: |
Source code in clickproof/closed_loop.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
assert_click_ok(store, attempt, **kwargs)
¶
Apply gate_click_attempt and raise :class:ClosedLoopError unless ok.
Source code in clickproof/closed_loop.py
assert_session_bootstrapped(store, session, *, app_name, **kwargs)
¶
Raise :class:ClosedLoopError unless session memory gate passes.
Source code in clickproof/closed_loop.py
assert_task_aligned(declared_task, proposed_action, **kwargs)
¶
Raise :class:ClosedLoopError unless :func:gate_task_alignment is ok.
Source code in clickproof/closed_loop.py
assert_usable_facts(source, **kwargs)
¶
Gate facts and raise :class:ClosedLoopError unless outcome is ok.
Source code in clickproof/closed_loop.py
gate_click_attempt(store, attempt, *, scorer=None, min_score_after=0.5, apply=True, miss_confidence_factor=0.25)
¶
Gate a click: OVERLAY-CLICK misses FAIL and invalidate the fact.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
FactStore
|
Fact store containing the target fact. |
required |
attempt
|
ClickAttempt
|
Click report from the computer-use runtime. |
required |
min_score_after
|
float
|
After a hit, require score >= this for PASS. |
0.5
|
apply
|
bool
|
If True, write refute/confirm + confidence decay to the store. |
True
|
miss_confidence_factor
|
float
|
Multiplier applied to confidence on miss. |
0.25
|
Returns:
| Type | Description |
|---|---|
GateOutcome
|
FAIL_LOUD if fact missing; FAIL on miss or post-hit unusable score; |
GateOutcome
|
PASS only on verified hit with usable score. |
Source code in clickproof/closed_loop.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 | |
gate_facts(source, *, min_score=0.5, app_name=None, require_usable=True, scorer=None)
¶
Read UI facts and fail loudly when the store is empty or unusable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
FactStore | Sequence[UIFact] | str | Path
|
Open :class: |
required |
min_score
|
float
|
Score threshold; facts strictly below this count as stale. |
0.5
|
app_name
|
str | None
|
Optional filter when reading from a store. |
None
|
require_usable
|
bool
|
If True, zero usable facts with some present is FAIL. |
True
|
scorer
|
FactScorer | None
|
Optional :class: |
None
|
Returns:
| Type | Description |
|---|---|
GateOutcome
|
class: |
Source code in clickproof/closed_loop.py
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
gate_session_memory(store, session, *, app_name, app_version=None, min_score=0.5, require_load_when_known=True, scorer=None)
¶
Gate session bootstrap against the durable fact store (GUI-MEMORY).
- Store has usable facts for app, session is
Noneor empty load → FAIL (re-discover trap - known UI not injected). - Store empty for app → FAIL_LOUD (nothing to remember; cold discover is expected but not a silent pass of "memory ok").
- Session loaded usable facts matching store → PASS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
FactStore
|
Durable :class: |
required |
session
|
SessionMemory | None
|
Result of :func: |
required |
app_name
|
str
|
Application under automation. |
required |
require_load_when_known
|
bool
|
If True (default), skip-load with known facts fails. |
True
|
Source code in clickproof/closed_loop.py
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 | |
gate_task_alignment(declared_task, proposed_action, *, allowed_actions=None, target=None, allowed_targets=None, refuse_high_risk_outside_allowlist=True, infer_from_task=True)
¶
Block adversarial CUA actions behind a legitimate task (Invisible Ink).
Public case (arXiv 2608.02018): Invisible Ink Threats - Adversarial Goals Behind Legitimate Tasks in Computer-Use Agents. The user/task text is benign; UI injection or model drift proposes delete/export/auth that was never authorized by the task.
Rules:
- Empty task or empty action → FAIL_LOUD
- Build allowlist from
allowed_actionsand/orinfer_allowlist_from_task - High-risk proposed action not in allowlist → FAIL (
human_required) - Any proposed action not in allowlist when allowlist non-empty → FAIL
targetnot inallowed_targetswhen both set → FAIL- In-scope action → PASS
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
declared_task
|
str
|
User/task description for this CUA step/session. |
required |
proposed_action
|
str
|
Tool/click/verb the agent wants to run. |
required |
allowed_actions
|
Sequence[str] | None
|
Explicit allowlist (overrides pure inference if set;
merged with inference when |
None
|
target
|
str | None
|
Optional UI target / path / element id. |
None
|
allowed_targets
|
Sequence[str] | None
|
Optional target allowlist. |
None
|
refuse_high_risk_outside_allowlist
|
bool
|
High-risk out-of-scope → FAIL. |
True
|
infer_from_task
|
bool
|
Merge heuristic verbs from task text into allowlist. |
True
|
Source code in clickproof/closed_loop.py
861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 | |
infer_allowlist_from_task(task)
¶
Heuristic allowlist from declared task text (no LLM).
Extracts simple verbs that appear as whole words and always includes a base set of safe navigation actions. High-risk verbs only enter the allowlist if the task text literally mentions them.
Source code in clickproof/closed_loop.py
is_high_risk_cua_action(action, *, extra=None)
¶
True if action is high-risk for computer-use (delete/export/auth/…).
Source code in clickproof/closed_loop.py
load_session_memory(store, app_name, *, app_version=None, session_id=None, min_score=0.5, scorer=None)
¶
Load known UI facts into a session (bootstrap for computer-use agents).
This is the load-bearing writer→reader path for GUI-MEMORY: call at session start so the agent does not re-discover controls every run.
Source code in clickproof/closed_loop.py
store_usable_count(store, app_name, *, app_version=None, min_score=0.5, scorer=None)
¶
Count usable facts in the store for app_name (no session load).
Source code in clickproof/closed_loop.py
analyze_cve(decision, *, required_sparse_keys=None, extra_sparse_keys=None, batch=None)
¶
Analyse one decision (and optional batch) for CVE failure modes.
Source code in clickproof/context_vars.py
assert_context_variables_ok(decision=None, **kwargs)
¶
Raise :class:ClosedLoopError unless :func:gate_context_variables is ok.
Source code in clickproof/context_vars.py
context_fingerprint(sparse)
¶
Stable fingerprint of sparse context for cross-context collapse checks.
Source code in clickproof/context_vars.py
gate_context_variables(decision=None, *, required_sparse_keys=None, extra_sparse_keys=None, batch=None, require_sparse_inventory=True, require_attended=True, refuse_dominant_only=True, refuse_cross_context_collapse=True)
¶
Refuse decisions that ignore sparse context (CVE / GeoReward class).
Rules:
- No decision when inventory required → FAIL_LOUD
- Required sparse keys missing/empty → FAIL_LOUD
- Sparse present but none attended → FAIL (overestimation of dominant cues)
- Dominant-only decision (dominant cues, no sparse attend) → FAIL
- Cross-context collapse (same choice across distinct markets) → FAIL
- Sparse attended, no collapse → PASS
Source code in clickproof/context_vars.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 | |
is_sparse_context_key(key, *, extra=None)
¶
True if key is a sparse decision-critical context variable.
Source code in clickproof/context_vars.py
to_markdown(facts_scores)
¶
Format facts and scores as a Markdown table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
facts_scores
|
list[tuple[UIFact, FactScore]]
|
List of (UIFact, FactScore) pairs. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Markdown string with a header and table. |