# Confidence gates
The `confidence` module requires a probability to be classified before its
value reaches confidence-sensitive code.
## Create a confident value
```rust
use requisite::prelude::*;
let forecast = Confident::new(true, 0.82)?;
```
`Confident::new` accepts finite values in `0.0..=1.0` and returns
`InvalidConfidence` for invalid input.
```rust
assert!(Confident::new((), f64::NAN).is_err());
assert!(Confident::new((), 1.1).is_err());
```
Use `confidence()` when telemetry or logging needs the original probability:
```rust
println!("model confidence: {:.2}", forecast.confidence());
```
## Gate an action
`gate` uses the default thresholds:
- `0.95..=1.0` produces `Gate::HighConfidence`.
- `0.60..0.95` produces `Gate::Likely`.
- Values below `0.60` produce `Gate::Unsure`.
```rust
match forecast.gate() {
Gate::HighConfidence(proof, value) => execute(proof, value),
Gate::Likely(value) => request_review(value),
Gate::Unsure(value) => record(value),
}
```
The high-confidence variant includes a `Certain` token. A sensitive function
can require that token:
```rust
fn execute(_proof: Certain, approved: bool) {
if approved {
charge_customer();
}
}
```
The token is private and is issued by the high-confidence branch of a gate.
## Configure thresholds
Use `Thresholds::new` to raise the certain boundary or change the likely
boundary:
```rust
let thresholds = Thresholds::new(0.75, 0.99)?;
match forecast.gate_with(thresholds) {
Gate::HighConfidence(proof, value) => execute(proof, value),
Gate::Likely(value) => request_review(value),
Gate::Unsure(value) => record(value),
}
```
The certain threshold has a floor of `Thresholds::MIN_CERTAIN`, currently
`0.95`. This keeps the meaning of `Certain` consistent across default and
custom gates.
`InvalidThresholds` exposes the requested `likely` and `certain` values for
error reporting:
```rust
let error = Thresholds::new(0.90, 0.80).unwrap_err();
eprintln!("invalid thresholds: {error}");
```
## Keep the value and proof together
Handle the `Gate` immediately after classification and pass the `Certain` token
with the value or operation it authorizes. This keeps the probability boundary
close to the resulting action and makes the decision path visible in ordinary
Rust control flow.