Safeguard
Developer Tools•

What is shrinking in property based testing, and why do QA teams care?

Shrinking reduces a failing random input to a small, readable one. Here is how it works in Hypothesis and why it makes security defects easier to report.

Safeguard Security Team
4 min read

Shrinking is the step where a property based testing tool takes a large failing random input and reduces it to a smaller one that still fails. QA teams care because a ten character failing input is a defect report a developer can act on, while a ten kilobyte one is noise.

The problem shrinking solves

Property based tools generate many inputs from rules you describe. When one breaks your property, the first failing input is usually messy: long strings, odd characters, deeply nested values. Reporting that as is would waste the developer's time.

Shrinking searches for a simpler input that triggers the same failure. The output is typically the smallest example the tool could find, which points straight at the faulty condition.

How Hypothesis handles it

In the Hypothesis documentation, shrinking is one of the phases of a test run, listed as shrinking failing test cases. Failures are also saved automatically in an example database, which the docs describe as best thought of as a cache that you never need to invalidate. By default it lives under .hypothesis/examples in the working directory.

Two details matter for QA:

  • The docs say not to rely on the database for correctness. To make sure Hypothesis always tries a particular input, add it with the @example decorator.
  • Explicit examples added with @example do not shrink. They are run as given, before random generation, which is what you want for a pinned regression.

A security flavored example

Imagine a function that normalizes file paths before checking they stay inside an upload folder. The property: after normalization, the result never escapes the folder.

The tool might first fail on a long string full of slashes and dots. After shrinking, the failing input could be a short sequence of dot segments. That short input does three jobs:

  1. It goes into the defect report as the reproduction.
  2. It becomes an @example so the fix stays fixed.
  3. It tells the developer which branch is wrong.

Workflow for a QA engineer

  1. Write a property in plain words first: "the resolved path always stays inside the base directory."
  2. Run the test and wait for a failure.
  3. Copy the shrunk input from the output, not the first raw failure.
  4. Confirm it fails on the current build and passes on the fixed build.
  5. Add it as an explicit example in the test file.
  6. Link the test from the ticket.

Limits to know

Shrinking finds a smaller failing input, not necessarily the smallest possible one, and different runs can end at different examples. Do not treat the shrunk value as the only trigger. Ask the developer whether neighbouring inputs also fail.

The database is a local cache, so a failure found on a colleague's machine or in CI will not appear on yours unless you share the directory or add an explicit example. Pinning the example is the reliable route.

Shrinking also depends on how the input strategy is described. Overly loose rules produce inputs a real user could never send, and a failure there may not matter. Tighten the rules to match what the application accepts, then judge severity on real reachability.

Try it yourself

Click through it at your own pace, or open it full screen. Notice how a finding only matters once you know the input can reach the code, the same question you should ask of a shrunk failure.

Safeguard's reachability analysis and free scan apply that question to dependency findings. It does not generate property tests for your own code.

Quick check

Does shrinking change what the bug is?

No. It looks for a simpler input that triggers the same failure, so the defect is the same but easier to read.

Do pinned examples shrink?

No. Hypothesis runs explicit examples as given and does not shrink them.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.