Auto (Zero-Config Evaluation)
stickler.auto
Zero-config evaluation of vanilla pydantic models.
Turn any pydantic.BaseModel (e.g. a Strands agent response_model) into a
scored stickler evaluation with a single call, with no StructuredModel subclass,
no JSON schema, no per-field configuration:
>>> import stickler
>>> result = stickler.evaluate(ground_truth, prediction)
>>> result.f1, result.field_scores
The comparison config (comparator, threshold, weight per field) is inferred
from each field's python type and name. See auto/README.md for the
inference rules and precedence.
evaluate, eval_for, EvalResult and EvalSpec are re-exported at the top level, so
stickler.evaluate and stickler.auto.evaluate are the same function. InferredSpec and
infer_field_config are public but only under stickler.auto.
Which path is this?
This is the inference path: it takes a live Pydantic class and infers a comparator and threshold per field from the type and the field name. The JSON Schema path takes a schema dict and reads structure only, never names, with different thresholds. See Choosing a Configuration Path.
stickler.auto.facade
Public zero-config evaluation surface.
The dead-simple entry point for evaluating structured output from a Strands agent (or any pydantic-producing system):
>>> import stickler
>>> pred = agent.structured_output(Invoice, "Extract the invoice: ...")
>>> result = stickler.evaluate(ground_truth, pred)
>>> print(result.f1, result.recall, result.field_scores)
No StructuredModel subclass, no JSON schema, no x-aws-stickler-*
annotations. Both arguments are ordinary pydantic instances; the comparison
config is inferred from their class (see :mod:.inference).
For a batch loop, compile once with :func:eval_for and reuse the returned
:class:EvalSpec.
stickler.auto.facade.evaluate(ground_truth, prediction, *, weight_hints=False, match_threshold=None)
Evaluate a prediction against ground truth with zero configuration.
ground_truth and prediction must be pydantic instances of the same
class (or a compatible superset, so extra/missing fields are tolerated). The
comparison config is inferred from their class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ground_truth
|
BaseModel
|
The reference instance. |
required |
prediction
|
BaseModel
|
The instance to score (e.g. a Strands |
required |
weight_hints
|
bool
|
Enable name-token weight heuristics (default off). |
False
|
match_threshold
|
Optional[float]
|
The similarity score at or above which an object
counts as a match (drives |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
An |
EvalResult
|
class: |
EvalResult
|
|
|
EvalResult
|
|
Source code in stickler/auto/facade.py
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 | |
stickler.auto.facade.eval_for(cls, *, weight_hints=False, match_threshold=None)
Compile a reusable :class:EvalSpec for a pydantic class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cls
|
Type[BaseModel]
|
The pydantic |
required |
weight_hints
|
bool
|
Apply name-token weight heuristics (default off, so
weights stay uniform and precision/recall are not skewed by guessed
business-criticality). Ignored for |
False
|
match_threshold
|
Optional[float]
|
The similarity score at or above which an OBJECT
counts as a match. It drives Left unset, a |
None
|
Source code in stickler/auto/facade.py
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 | |
stickler.auto.facade.EvalSpec
A compiled, reusable evaluator for one pydantic class.
Build once with :func:eval_for, then call :meth:evaluate per pair. The
inferred shadow StructuredModel is cached, so this is the efficient path
for evaluating a dataset.
Source code in stickler/auto/facade.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 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 | |
evaluate(ground_truth, prediction)
Score a single ground-truth / prediction pair.
Accepts instances of the source class or plain dicts (e.g. rows loaded from a JSON dataset); dicts are validated into the source class first, so type coercion and error messages come from the user's own model.
Source code in stickler/auto/facade.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
explain()
Return {field: {comparator, threshold, weight, source, why}}.
Makes every choice auditable. why is the ordered provenance trail;
source is a coarse label (type / name-token / degrade,
or explicit for a passthrough StructuredModel).
Source code in stickler/auto/facade.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
stickler.auto.facade.EvalResult
Flat, friendly view over a stickler comparison result.
Wraps the nested dict returned by StructuredModel.compare_with and
exposes the metrics users actually reach for. The full raw dict is always
available via :attr:raw.
Source code in stickler/auto/facade.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | |
non_matches
property
The per-field failure records, computed on first access.
Not requested during evaluate(). document_non_matches=True costs
roughly 2x on a 40-item document, flat whether one field fails or all of
them, and the callers who want these records are printing a report rather
than scoring a corpus. Computed here instead, once, and cached.
Returns an empty list when the pair cannot be recompared (an
EvalResult built directly from a raw dict, as some tests do), falling
back to whatever the raw dict already carries.
explain()
Per-field config + provenance, joined with THIS pair's scores.
Extends :meth:EvalSpec.explain with what actually happened for this
comparison: score (post-threshold), raw_similarity (before
clipping, when the engine reports it), and a human-readable
verdict such as "raw 0.56 < threshold 0.85 -> clipped to 0.0"
so a 0.0 is distinguishable between a near-miss and a total mismatch.
Source code in stickler/auto/facade.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
EvalResult attributes
Set in __init__ from the raw comparison dict, so they do not appear in the generated signature
above:
| Attribute | Type | Value |
|---|---|---|
overall_score |
float |
Weighted average of all field scores |
field_scores |
dict[str, float] |
Per-field score, after threshold clipping |
precision |
float |
cm_precision from the overall confusion matrix |
recall |
float |
cm_recall |
f1 |
float |
cm_f1 |
accuracy |
float |
cm_accuracy |
matched |
bool |
overall_score >= match_threshold. A convenience roll-up, not a per-field guarantee: individual fields can be below their thresholds while matched is True. Read field_scores or the confusion matrix for that. |
confusion_matrix |
dict |
The full confusion-matrix subtree |
raw |
dict |
The unmodified compare_with() result |
Auditing the inferred config
explain() reports what was chosen and why, so an inferred evaluation is never a black box:
result = stickler.evaluate(gt, pred)
result.explain()["invoice_id"]
{'comparator': 'ExactComparator',
'threshold': 1.0,
'weight': 1.0,
'clip_under_threshold': True,
'source': 'name-token',
'why': ['type:str -> LevenshteinComparator@0.7',
'name-token:invoice_id -> ExactComparator@1.0'],
'score': 0.0,
'raw_similarity': 0.0}
why is the ordered trail: the type signal fired first, then the name token overrode it. Calling
explain() on the EvalSpec instead omits score and raw_similarity, since no pair has been
scored yet — use it to review the configuration before running a dataset.
Inference
The rules behind every decision above, plus the precedence between the type signal and the
name-token refinement, are documented in
src/stickler/auto/README.md.
stickler.auto.inference
Zero-config comparator inference for vanilla pydantic fields.
This module is the "brain" behind :func:stickler.evaluate. Given a single
pydantic FieldInfo (the live one from cls.model_fields, never a
JSON-schema round-trip) it decides which comparator/threshold/weight the field
should be evaluated with, so an unconfigured model still gets a sensible,
type-aware evaluation instead of the blind string-edit-distance fallback the
raw comparison engine applies to unannotated fields.
Design rules (see auto/README.md):
- Type first. The python annotation is the highest-value, always-present
signal.
bool/Enum/Literal-> Exact,int-> Numeric(exact),float-> Numeric(tolerant),date/datetime-> Date,str-> Levenshtein. - Name tokens refine. Field-name tokens (
id,amount,email...) sharpen the comparator/threshold on top of the type default. - Weights are honest. Business-criticality is not encoded in a vanilla
model, so weights default to
1.0. Name-token weight bumps are opt-in viaweight_hints=Trueand always recorded in provenance. - Never surprise. Semantic/BERT/LLM comparators are never auto-selected; a comparator that is unavailable in this environment degrades to Levenshtein/Exact and the degrade is recorded.
The public entry point is :func:infer_field_config, which returns an
:class:InferredSpec. The builder turns that spec into a (type, Field)
tuple for ModelFactory.create_model_from_fields.
stickler.auto.inference.infer_field_config(field_name, field_info, *, weight_hints=False, registry=None, match_threshold=None)
Infer a comparison spec for one pydantic field.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
field_name
|
str
|
The field's name (drives name-token heuristics). |
required |
field_info
|
FieldInfo
|
The live |
required |
weight_hints
|
bool
|
When True, apply name-token weight bumps. When False (default) all weights stay 1.0 so precision/recall are not skewed by guessed business-criticality. |
False
|
registry
|
Optional[ComparatorRegistry]
|
Comparator registry for the availability gate. Defaults to the global registry. |
None
|
match_threshold
|
Optional[float]
|
Object-level match threshold, used as the FIELD
threshold for dict-typed fields so they are not exempt from a value
the caller set. Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
An |
InferredSpec
|
class: |
InferredSpec
|
fields are NOT resolved here (the builder detects and recurses on them); |
|
InferredSpec
|
this function only handles primitive and primitive-list fields. |
Source code in stickler/auto/inference.py
458 459 460 461 462 463 464 465 466 467 468 469 470 471 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 | |
stickler.auto.inference.InferredSpec
dataclass
Resolved comparison configuration for a single field.
Everything the builder needs to emit a ComparableField plus the
provenance surfaced through EvalResult.explain().
Source code in stickler/auto/inference.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
source
property
Coarse origin label for the final comparator decision.
A name-token rule that MATCHED but was refused as incompatible with the
field's type did not drive the decision -- the type default did -- and is
recorded under _NAME_TOKEN_REFUSED rather than _NAME_TOKEN_APPLIED for
exactly that reason. Counting it made a str field named issued_date
report name-token while carrying the plain LevenshteinComparator@0.7
that its type alone produced, telling a reader the name had been honoured
in the one case where it was explicitly not.