Skip to main content

Confidence Levels

Every repair response includes a confidence score: high, medium, or low.

The Three Levels


How Confidence is Calculated

Shim uses monotonic pessimistic scoring: any low-confidence repair downgrades the entire score.

Scoring Rules

Why Pessimistic?

Contract: Confidence never overstates safety. high means truly safe. low means truly risky.

High Confidence

Repairs Applied

  • Closing brackets: {"name": "John"{"name": "John"}
  • Trailing commas: {"a": 1, "b": 2,}{"a": 1, "b": 2}
  • Markdown fences: ```json {"a": 1} ```{"a": 1}
  • Smart quotes: {"name": "John"}{"name": "John"}
  • Leading/trailing text: Here's the data: {"a": 1}{"a": 1}

Why High?

These are unambiguous structural fixes. No semantic changes. No data loss.

Example Response

What to Do

Use immediately. No review needed.

Medium Confidence

Repairs Applied

  • Type coercion: "30"30
  • Unquoted keys: {name: "test"}{"name": "test"}
  • Unquoted values: {status: active}{status: "active"}
  • JavaScript values: NaNnull, Infinitynull
  • Single quotes: {'key': 'value'}{"key": "value"}

Why Medium?

These are policy decisions. Safe, but not unambiguous. Example: "30" could be a string or number. Shim coerces based on schema.

Example Response

What to Do

Use immediately, but log for review.

Low Confidence

Repairs Applied

  • Ambiguous type inference (no schema provided)
  • Multiple repair interpretations possible
  • Complex nested structure repairs

Why Low?

Shim had to guess at the correct fix. Multiple interpretations were possible.

Example Response

What to Do

Alert for manual review.

Perfect Input (High Confidence)

Meaning

Input was already valid JSON. No repairs needed. Confidence is still high.

Example Response

What to Do

Use immediately. Check was_repaired: false to distinguish perfect input from repaired input.

Confidence by Repair Type


Strict vs Lenient Mode

Mode affects warnings, not confidence:

Strict Mode (default)

High-severity warnings become errors. Repair fails.

Lenient Mode

All warnings allowed. Repair succeeds.

Best Practices

1. Always Provide Schema

Schema enables high-confidence type coercion:

2. Log Medium/Low Repairs

Track repair patterns over time:

3. Alert on Low Confidence Spikes

4. Review Repair Logs

Check dashboard for confidence distribution:

Next Steps

Response Object

Full response schema

Error Handling

Handle low confidence repairs

Schema Validation

Improve confidence with schemas

Troubleshooting

Debug confidence issues