Repository navigation
Filter Rules
Checked against v0.7.6 on November 13, 2026.
This page covers the two filters that run before any model sees a posting: the area and title drop at ingest, which decides what is stored at all, and Tier 0, the rule layer that sorts what was stored. It explains filters.yml, the helper whitelist, how to add a helper, and why generator expressions are banned. For where Tier 0 sits in the pipeline, see Architecture overview.
Tier 0 is pure Python. It costs no model time. Each rule is a short expression, and the whitelisted helpers in kestrel/rules/helpers.py do the actual work.
Before Tier 0 sees anything, run_source() in kestrel/ingest/runner.py discards two kinds of clear mismatch. This is not Tier 0 and it does not read filters.yml. A dropped posting is never normalized, stored or scored, so it costs no database row and no model time. It is built to drop only what is clearly wrong (hard rule 4).
For each fetched posting, in order:
-
Outside the search area.
_outside_area()splitslocation_rawon;and|into places and parses each withparse_location()inkestrel/ingest/location.py. The posting is dropped only when every place names a known country that is not in the profile'sgeo_rules.remote_country_allowlist. A posting listed in several places ("New York, NY; London, GB") stays when any one is in the area. A place with no recognizable country, no location at all, or an empty allowlist keeps the posting. The country table is the full ISO 3166 list (alpha-2, alpha-3, numeric, names and aliases), vendored askestrel/resources/iso3166.csvand read withimportlib.resources. This test judges where, never how: "New York - Remote" passes because a US place is in the area, and whether a role is really remote or hybrid is left to scoring. -
Unrelated title.
smart_filter.keep()inkestrel/ingest/smart_filter.pyreturns false when the title's seniority is known and below the profile's seniority floor, or when the title has field words and none of them overlap the operator's. The operator's field words come from their target titles and those titles' phrasings, plus any word found in the titles of at least two of their own pursuits (MIN_PURSUITS).build_context()reads them fresh at the start of every run, so a profile edit or a new pursuit applies on the next run. A blank title, an unknown level, a title with no field words, or a profile with nothing to compare against all keep the posting.
The filter covers searches and every company board, since both go through run_source(). It does not run for manual paste (kestrel/ingest/manual.py), imported applied roles, or SEC trigger signals (kestrel/ingest/signal_runner.py), which call normalize_and_store() directly.
Nothing is dropped silently. The run counts each drop in scrape_run.counts as dropped_outside_area and dropped_unrelated_title, the Runs drawer shows them as "Skipped N: x outside your area, y unrelated titles", and the diagnostics bundle carries the same two numbers. The stored postings are unaffected.
tests/test_ingest_area.py and tests/test_ingest_titles.py cover the two drops and their counts, with tests/test_location.py and tests/test_smart_filter.py under them.
This replaced an older design in which such roles were stored and held in a background lane to be scored when the machine was idle. kestrel/pipeline/lane.py remains only to drain rows stored under that design: no new roles enter it, and each leftover row is rechecked with the same two tests (reject_mismatch()) before release. A leftover row that now fails is set to t0_reject with a reason that starts outside_area: or unrelated_title:. Tier 0 then treats it like any other rejected role.
run_tier0_batch() in kestrel/pipeline/tier0.py walks every opportunity at stage new that is not archived. For each one, evaluate_tier0() does this:
- Hard blockers run in file order. The first one whose
when:is true rejects the role. The stage becomest0_rejectandstage_reasonis stored asblocker:<rule id>: <reason>. A blocker the operator switched off for that track (Tier0.rules_off, see the last section) is skipped, and so is every blocker for a role the operator chose to score anyway. - If no blocker fires, every soft signal that is true adds its
weightto apre_score. The stage becomest0_pass,stage_reasonlists the soft hits (andgeo_uncertainortier0_overridewhen they apply), and onet1task is enqueued with priorityint(pre_score * 100), so the best candidates get model time first. - Each opportunity is committed on its own, so a killed process resumes cleanly (hard rule 5 in
CLAUDE.md).
Tier 0 only rejects or passes. A soft signal can lower a score, but it never rejects. A rule that raises an exception is logged (tier0_rule_error or tier0_soft_error) and skipped, so a broken rule keeps roles rather than dropping them.
Uncertainty passes. Hard rule 4 in CLAUDE.md says a wrongly rejected role is invisible, while a wrongly kept one costs seconds. That is why the shipped seniority_floor blocker tests seniority_rank(opp.title) >= 0 first (an unknown title ranks -1), and why stale and stale_trigger test is not None before comparing dates.
The shipped default is kestrel/resources/config/filters.yml. On first run, paths.seed_config() copies it into the config folder, but only when that folder holds no *.yml files yet. After that, paths.config_file("filters.yml") returns your copy if it exists and the packaged one otherwise. Upgrading Kestrel does not rewrite your copy.
The file is keyed by track, then by group:
employment:
hard_blockers:
- id: anti_title
when: "title_contains_any(opp, profile.employment_terms.anti_titles)"
reason: "Excluded title"
soft_signals:
- { id: fresh, when: "age_days(opp.date_posted) <= 3", weight: 0.5 }
consulting:
hard_blockers: []
soft_signals: []Hard blockers take id, when and reason. Soft signals take id, when and weight (negative weights are allowed). There is no verdict or destination field.
Expressions see five names: opp, org, profile, source and settings. profile is the track's block from profile.yml as nested attributes (kestrel/pipeline/profile.py), so the paths look like profile.employment_terms.comp_floor_usd, profile.must_have and profile.requires_sponsorship. settings is the typed settings object, which is where settings.max_posting_age_days (default 45) and settings.consulting.max_trigger_age_days (default 120) come from (kestrel/config.py).
Employment hard blockers, in evaluation order: comp_floor, sponsorship, clearance, anti_title, seniority_floor, geo, stale.
Employment soft signals: title_exact (+2.0), title_contains (+1.0), near_floor (0.0), comp_above_target (+1.0), direct_ats (+0.8), fresh (+0.5), must_have_hit (+0.5), comp_unknown (-0.3), must_avoid_hit (-1.0), staffing_agency (-1.0), reposted_often (-0.8), likely_ghost (-1.2).
Consulting hard blockers: rate_floor, too_short, excluded_sector, geo, stale_trigger.
Consulting soft signals: near_floor (0.0), pe_backed (+1.5), target_size (+1.0), target_sector (+1.0), recent_trigger (+1.2), multi_signal (+1.5), no_url (-0.2).
direct_ats is true when source_kind_in finds the source's kind in a list of 14 kinds in the file: greenhouse, lever, ashby, workday, smartrecruiters, rippling, adp, paylocity, workable, teamtailor, recruitee, personio, breezy and careers_page. A kind you add to the adapter registry is not in that list until you add it to the rule (a seeded copy of filters.yml keeps the list it was seeded with).
comp_floor and rate_floor do not reject at the exact floor. They compare the posted maximum against margin_floor(floor, margin_pct), with the percentage from comp_floor_margin_pct or day_rate_floor_margin_pct in the profile. The margin is one of five stops, 0 (exact), 2, 5, 10 or 15 percent, and an unset or off-stop value reads as 5 (kestrel/rules/margin.py). A role whose maximum is under the floor but inside the margin is kept, and the near_floor soft signal (weight 0, so it never changes the score) tags it "Below your minimum" in stage_reason. A role with no posted pay never trips either blocker. If your filters.yml still holds the two pre-margin blocker lines exactly as they once shipped, _upgrade_shipped_blockers() rewrites them at load time and appends the near_floor signal.
Most numbers a rule compares against come from your profile or the Core settings tab, not from the file. The Filters tab says as much and notes that the rules' own logic "should not need editing."
Every helper lives in kestrel/rules/helpers.py and is registered by name in build_evaluator(). Anything not in that dictionary is an unknown symbol.
| Helper | What it does |
|---|---|
regex(text, pattern) |
re.search; False for non-strings |
age_days(value) |
Days since a date or ISO string; returns 999999 for None or unparseable |
seniority_rank(title) |
0 to 8 from the ladder in _SENIORITY; -1 for unknown |
title_contains_any(opp, terms) |
Strict lowercase substring match on the title |
title_equals_any(opp, terms) |
Strict lowercase exact match |
title_near_any(opp, terms), title_near_equals_any(opp, terms)
|
Token-set matching via kestrel/rules/titles.py; soft signals only |
desc_contains_any(opp, terms) |
Substring match on description_md
|
value_in(value, choices) |
Case-insensitive membership for strings |
source_kind_in(source, kinds) |
value_in on source.kind
|
comp_max_below(opp, n), comp_max_at_least(opp, n)
|
False when either side is None
|
margin_floor(floor, pct), comp_max_near_floor(opp, floor, pct)
|
The lowest passing maximum, and whether a posted maximum sits under the floor but inside the margin (kestrel/rules/margin.py) |
trigger_int_below(opp, key, n) |
Reads an integer from opp.trigger_data
|
org_signal_count(org, days) |
Counts org.signals within the window; undated signals count |
geo_allows(opp) |
Name matching against the profile's geo_rules, never distance |
len, min, max, abs
|
Plain built-ins |
Every helper is null-safe. A None in gives the safe answer out: False for predicates, the 999999 sentinel for age_days. Note what that means for age_days(opp.date_posted) <= 3: a missing date reads as very old, so the fresh bonus does not apply, and the stale blocker has its own is not None guard for the same reason.
anti_title uses strict title_contains_any, so it never widens. The near-title helpers are for soft signals only, because a wider match in a blocker rejects more roles. If your filters.yml was seeded before near titles existed, _upgrade_shipped_soft() rewrites the two untouched title_exact and title_contains lines at load time. Edited rules and all hard blockers are read as written.
geo_allows (geo_evaluate() in kestrel/rules/helpers.py) works in order:
- A remote role in an allowed or unparsed country passes.
- An on-site or hybrid role passes when you listed no on-site states or metros, because an empty list must never mean "nowhere".
- A parsed state in your on-site states passes.
- A parsed city that matches a metro alias passes.
- A
location_rawthat contains an alias passes. - An unknown remote type is denied when the posting names a specific place (a parsed state, or a city that is not a vague phrase such as "multiple locations" or "2 Locations") and neither the title, the location nor the description says remote, hybrid, work from home or telecommuting. Such a posting is on-site there. The role stays in the set-aside list and can be restored in one click.
- Any other unknown remote type passes and sets
geo_uncertain.
A role with a known remote type that matched nothing above is denied.
There is no geocoder in this stack (CLAUDE.md). The ingest country drop above is separate from this helper: it removes a clearly foreign country before storage, while geo_allows runs on stored roles and handles states, metros and remote wording.
A rule like any(t in opp.title for t in profile.target_titles) is a generator expression, and it is banned. CLAUDE.md and SPEC.md section 6.1 now agree with the code on how the ban works. The code comment in kestrel/rules/helpers.py notes that EvalWithCompoundTypes in simpleeval 1.0.7, which Kestrel needs so that list literals such as ['greenhouse', 'lever'] work in source_kind_in, would evaluate a generator expression. So the ban does not rely on simpleeval failing. check_filters() runs _assert_no_comprehensions, which parses each when: with ast.parse and rejects GeneratorExp, ListComp, SetComp, DictComp and Lambda nodes before evaluating anything, at config load and with a message that names the rule. Do not remove or loosen that guard. List and dict literals are allowed. The reasons for the ban are the same either way: the rule language stays small, every list operation is a named and tested helper, and a rule cannot do anything the helpers do not allow.
tests/test_filters_load.py guards this. It checks that the packaged file evaluates cleanly, that a generator expression is rejected directly and when wrapped in max(...), that list literals still pass, and that an unknown symbol fails. Keep it green.
check_filters() evaluates every rule once against a reference context from kestrel/rules/sample.py, built from the fictional example profile. It runs in two places:
- Preflight (
_check_configinkestrel/doctor.py). A failure there is a blocking "Config valid" fail that names the track, group and rule id. See Preflight and diagnostics. - The test suite.
It does not run on every Tier 0 sweep. At sweep time a bad rule is logged and skipped, which is why preflight matters after you edit the file.
- Write a null-safe function in
kestrel/rules/helpers.py. AcceptNoneand wrong types, and return the safe answer instead of raising. - Register it in the
functionsdictionary insidebuild_evaluator(). There is no separate registry. - Use it from
filters.yml, and add a call totests/test_filters_load.pyortests/test_pipeline_tier0.pyso the rule is exercised. - If the helper needs a symbol from the profile, populate it in
kestrel/resources/config/profile.example.yml, because the sample context is built from that file. - If the helper backs a hard blocker, check what the operator sees on rejection (next section).
- Run
uv run --extra dev python scripts/check.py, as described in Contributing.
Prefer a helper that takes opp and a list over one that takes pre-extracted strings. It keeps the YAML short and the null handling in one place.
def desc_mentions_any(opp: Any, terms: Any) -> bool:
desc = _lower(getattr(opp, "description_md", None))
if not desc or not terms:
return False
return any_substr(desc, terms)Settings, Which roles you see (kestrel/web/pages/settings_roles.py) is where an operator works with the hard blockers. For each shipped blocker (RULES in kestrel/web/settings_view.py) it shows a switch, how many of the last 200 roles the rule would set aside, and a "See them" list. Counts and lists never include a role with nothing for the rule to check, such as no posted pay or no clearance statement (hard rule 4). The pane also edits the two rules that take a number: how many days old a role may be (1 to 365) and how many weeks short a project may be (1 to 52). The pay, titles, level and places a rule compares against are edited in Profile, not here.
-
Switch a rule off. The id goes into the setting
tier0.rules_off.<track>(Tier0.rules_offinkestrel/config.py), andevaluate_tier0()skips that blocker. Nothing is deleted. A switch-off or a loosened number queues at0_rechecktask (kestrel/pipeline/recheck.py) that re-runs the rules with no model over the active roles att0_rejectand moves each one that now passes back tonew. The same recheck runs after a profile save that changes what the rules read, and it never touches a role the operator chose to score anyway, labeled or pursued. An unknown id inrules_offis ignored, so removing a rule in a later version never breaks loading. -
Show it anyway. On one set-aside role in the "See them" list,
POST /settings/roles/show/{id}returns the role tonew, records the choice so Tier 0 never sets it aside again for that rule, and offers Undo. -
Hand-edited rules. A blocker you add to
filters.ymlruns, but it has no switch in this pane because the pane lists the shipped ids only. There is still no expression tester.
On a rejected role, explain_rule() in kestrel/web/fit.py turns blocker:<id> into plain words and a "Change it in" link. The mapping is a fixed table, _RULE_HOME, keyed by the exact ids of the shipped blockers. A rule id you add yourself shows "Set aside by one of your rules" with a link to Settings. If you add a blocker, you can add an entry to _RULE_IDS and _RULE_HOME for a friendlier sentence, but it is optional.
"Score this role anyway" is the per-role override. It queues a t1 task flagged tier0_override, and Tier 1 records tier0_override.<opportunity id> in the same commit as its result (kestrel/services/tier0_override.py, kestrel/queue/rescore.py). A task that dies records nothing. Your rules never change, and later Tier 0 passes skip blockers for that role while still computing its soft score.
GET /settings/filters/preview and _filter_preview in kestrel/web/pages/settings.py are the older read-only per-rule count over the last 200 roles. No template links to them any more; the Which roles you see pane gets the same figure from rule_counts() in kestrel/web/settings_view.py.
None of this touches the outside world. Tier 0 reads postings Kestrel already fetched. Kestrel never submits an application, sends a message or acts on a third-party site for you.
Start here
Interfaces
Extending Kestrel
How it works
- Prompts and context budgets
- Document engine
- Learning loop internals
- Analytics internals
- Task queue and concurrency
- Database schema
Shipping and safety
- Packaging and releases
- Preflight and diagnostics
- Security and privacy model
- Outbound calls
- Benchmarking
Workarounds and Troubleshooting