Functional Weave
Code in Rust

property.deposit-cap Unreviewed

Maximum tenancy deposit a landlord may take: five or six weeks' rent under the Tenant Fees Act 2019.

1.0.2 · published 2026-10-03 by charlie · Anterra

Pinned by 19 tests, run in TypeScript, Python and Rust.

Unreviewed. This capability’s implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified conveyancer or tax adviser has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.

Not professional advice. This capability calculates property figures from published rules. It is a software component for developers, not legal or financial advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed in its README, and have a conveyancer or tax adviser review how you use it, before anyone relies on the output. Provided “as is” under its licence, without warranty.

What it does

The most a landlord or letting agent in England may take as a tenancy deposit: five weeks' rent when the annual rent is under £50,000, six weeks' rent when it is £50,000 or more. Anything above the cap is a prohibited payment.

`depositCap(money(100000, "GBP"), "monthly", "england", "2026-09-01")` is a maximum of £1,153.84: £1,000 × 12 = £12,000 a year, under £50,000, so five weeks, and £12,000 × 5 ÷ 52 = £1,153.846…

For example

  • deposit_cap(£1,000.00, monthly, england, 2026-09-01) → annual rent £12,000.00, weekly rent £230.76, weeks 5, maximum £1,153.84 £1,000 a month: five weeks is £1,153.84 (rounded down from £1,153.846)
  • deposit_cap(£240.00, weekly, england, 2026-09-01) → annual rent £12,480.00, weekly rent £240.00, weeks 5, maximum £1,200.00 £240 a week: five weeks is exactly £1,200 (the guidance's joint-tenancy example)
  • deposit_cap(£4,166.66, monthly, england, 2026-09-01) → annual rent £49,999.92, weekly rent £961.53, weeks 5, maximum £4,807.68 £4,166.66 a month is £49,999.92 a year: still five weeks

The function

The same function in TypeScript, Python and Rust, pinned by the same tests. Pick your language; the choice follows you around the registry.

pub fn deposit_cap(rent: &Money, rent_period: &str, jurisdiction: &str, on_date: &str) -> DepositCap
rentMoneythe total rent for the whole tenancy (all joint tenants together), in GBP, zero or more
rent_periodRentPeriodwhat one payment of rent covers
jurisdictionstring"england"; the only one with data so far
on_datedatethe date the tenancy is granted, renewed or continued
returnsDepositCap

The types it declares, generated into your project

// RentPeriod is a string in Rust, one of: "weekly", "monthly", "annual".
// Parameters take it as &str and results hold it as String.

/// The cap and how it was reached.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DepositCap {
    /// rent for a year: weekly × 52, monthly × 12, or the annual rent
    pub annual_rent: Money,
    /// annual rent ÷ 52, rounded down to the penny
    pub weekly_rent: Money,
    /// 5 below the threshold, 6 at or above it
    pub weeks: i64,
    /// annual rent × weeks ÷ 52, rounded down to the penny
    pub maximum: Money,
}

Your code names it in one line, in the file that uses it

fune!(property.deposit-cap@^1);  // then call deposit_cap(…)
impl/rust.rs · 108 lines · open · raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

use super::funejson::Value;  ← the fune runtime: the JSON value the test vectors use; fune build keeps it only where a signature takes one
use super::money_amount::{money, money_from_value, money_to_value, Money};  ← from money.amount ^1.0.0 · built alongside by fune
use super::property_deposit_cap_data::{DepositCapRule, DEPOSIT_CAPS, DEPOSIT_CAPS_HISTORY};  ← this capability’s own data, compiled from data/deposit-caps.json into the same file by fune build

// Keeps annual rent × 6 exact as a JavaScript number; the same limit here.
const MAX_MINOR: i64 = 1_000_000_000_000;

fn is_iso_date(value: &str) -> bool {
    let bytes = value.as_bytes();
    bytes.len() == 10
        && bytes.iter().enumerate().all(|(i, b)| if i == 4 || i == 7 { *b == b'-' } else { b.is_ascii_digit() })
}

fn find_rule(jurisdiction: &str, on_date: &str) -> &'static DepositCapRule {
    let mut best: Option<&'static DepositCapRule> = None;
    let mut earliest: Option<&'static str> = None;
    for rule in DEPOSIT_CAPS {
        if rule.jurisdiction != jurisdiction {
            continue;
        }
        if earliest.map_or(true, |e| rule.valid_from < e) {
            earliest = Some(rule.valid_from);
        }
        if on_date < rule.valid_from {
            continue;
        }
        if let Some(to) = rule.valid_to {
            if on_date > to {
                continue;
            }
        }
        if best.map_or(true, |b| rule.valid_from > b.valid_from) {
            best = Some(rule);
        }
    }
    if let Some(rule) = best {
        return rule;
    }
    // A build installed with a pruned history must not answer an old date
    // with today's rule, so it says what happened instead.
    if DEPOSIT_CAPS_HISTORY != "full" {
        if let Some(e) = earliest {
            if on_date < e {
                panic!(
                    "no deposit cap rule for {} on {}: this build was installed with history={}, so it only carries rules from {}",
                    jurisdiction, on_date, DEPOSIT_CAPS_HISTORY, e
                );
            }
        }
    }
    panic!("no deposit cap rule for {} on {}", jurisdiction, on_date)
}

/// The maximum tenancy deposit: five weeks' rent below the annual-rent
/// threshold, six at or above it. The threshold is tested on the exact annual
/// rent, and the cap is annual rent × weeks ÷ 52 rounded down once, so it can
/// never sit a fraction of a penny over the statutory limit.
///
/// # Panics
/// Panics on a malformed date, rent not in GBP or negative, an unknown rent
/// period, or no rule for the jurisdiction on that date.
pub fn deposit_cap(rent: &Money, rent_period: &str, jurisdiction: &str, on_date: &str) -> DepositCap {
    if !is_iso_date(on_date) {
        panic!("onDate must be an ISO date (YYYY-MM-DD), received \"{}\"", on_date);
    }
    if rent.currency != "GBP" {
        panic!("rent must be in GBP, received {}", rent.currency);
    }
    if rent.minor < 0 {
        panic!("rent must not be negative, received {}", rent.minor);
    }
    let annual = match rent_period {
        "weekly" => rent.minor.checked_mul(52),
        "monthly" => rent.minor.checked_mul(12),
        "annual" => Some(rent.minor),
        other => panic!("unknown rent period \"{}\"", other),
    };
    let annual = match annual {
        Some(a) if a <= MAX_MINOR => a,
        _ => panic!("annual rent must be at most {} minor units", MAX_MINOR),
    };
    let rule = find_rule(jurisdiction, on_date);
    let weeks = if annual < rule.annual_rent_threshold_minor { rule.weeks_below } else { rule.weeks_at_or_above };
    DepositCap {
        annual_rent: money(annual, "GBP"),
        weekly_rent: money(annual / 52, "GBP"),
        weeks,
        maximum: money(annual * weeks / 52, "GBP"),
    }
}

pub fn deposit_cap_to_value(cap: &DepositCap) -> Value {
    Value::obj(vec![
        ("annualRent", money_to_value(&cap.annual_rent)),
        ("weeklyRent", money_to_value(&cap.weekly_rent)),
        ("weeks", Value::Int(cap.weeks)),
        ("maximum", money_to_value(&cap.maximum)),
    ])
}

pub fn fune_vector(args: &[Value]) -> Value {
    deposit_cap_to_value(&deposit_cap(
        &money_from_value(&args[0]),
        args[1].as_str(),
        args[2].as_str(),
        args[3].as_str(),
    ))
}

Install

fune build

With that line in your source, in a Rust project (language rust in fune.project), fune build resolves it and its 1 dependency, pins them in fune.lock, downloads only the Rust package of each, and builds the code above into your project’s .fune/build, one readable file per capability with a header linking back here. A crate’s build.rs runs it before every compile. Or pin a range in fune.project and build in one step:

fune add property.deposit-cap
Download for Rust property.deposit-cap-1.0.2-rust.fune · 19,655 bytes sha256 677c4ab2eabf838649c2f9a0520c1c50d1dc9a20b927a0229a87d52e2cf7382d

The manifest, vectors and README with only the Rust implementation. Install it without the registry with fune add ./property.deposit-cap-1.0.2-rust.fune, or fetch it from a terminal with fune pull property.deposit-cap@1.0.2:rust.

The whole function, every language, is one file too: property.deposit-cap-1.0.2.fune, 25,804 bytes, sha256 95c34f3aa1cf27cc69d6a003d2105754225142fe70affebf4fca94b38300fb8e. It installs into a project of any language.

Customise it in your app

The seams this capability offers. Put a marker directly above a function of your own and fune build wires it into the built code; the package on the registry is not changed, the built file’s header lists it under CUSTOMISED, and fune hooks lists every hook in the project. How hooks work.

before — your function gets the arguments and returns them, changed or not, or throws to refuse the call.

// fune: before property.deposit-cap

after — your function gets the result and the arguments, and returns the final result.

// fune: after property.deposit-cap

replace — inside this capability’s code only, calls to a dependency go to your function, with the same signature. Other capabilities that use it are unaffected; write in * to replace it everywhere.

// fune: replace money.amount in property.deposit-cap

step — your function runs at a numbered point inside the function’s body, receives the in-scope values it names as parameters, and may return replacements. List the points with fune show property.deposit-cap --steps.

// fune: step property.deposit-cap after <n|label>

Tests

A version published now needs at least 8 tests for every function, and one that expects the error for each function that throws; the registry refuses it otherwise. fune verify --all runs each case in TypeScript, Python and Rust, and a project runs them again with fune verify. This page lists the cases; it does not run them. The exact JSON is vectors.json.

CaseArgumentsExpected
£1,000 a month: five weeks is £1,153.84 (rounded down from £1,153.846) £1,000.00, monthly, england, 2026-09-01 → annual rent £12,000.00, weekly rent £230.76, weeks 5, maximum £1,153.84
£240 a week: five weeks is exactly £1,200 (the guidance's joint-tenancy example) £240.00, weekly, england, 2026-09-01 → annual rent £12,480.00, weekly rent £240.00, weeks 5, maximum £1,200.00
£4,166.66 a month is £49,999.92 a year: still five weeks £4,166.66, monthly, england, 2026-09-01 → annual rent £49,999.92, weekly rent £961.53, weeks 5, maximum £4,807.68
£4,166.67 a month is £50,000.04 a year: six weeks £4,166.67, monthly, england, 2026-09-01 → annual rent £50,000.04, weekly rent £961.53, weeks 6, maximum £5,769.23
exactly £50,000 a year is six weeks, not five £50,000.00, annual, england, 2026-09-01 → annual rent £50,000.00, weekly rent £961.53, weeks 6, maximum £5,769.23
£49,999.99 a year is five weeks £49,999.99, annual, england, 2026-09-01 → annual rent £49,999.99, weekly rent £961.53, weeks 5, maximum £4,807.69
£961.54 a week (£50,000.08 a year): six weeks, exactly 6 × weekly £961.54, weekly, england, 2026-09-01 → annual rent £50,000.08, weekly rent £961.54, weeks 6, maximum £5,769.24
£961.53 a week (£49,999.56 a year): five weeks £961.53, weekly, england, 2026-09-01 → annual rent £49,999.56, weekly rent £961.53, weeks 5, maximum £4,807.65
the cap is not five times the rounded weekly rent: £1,250 a month £1,250.00, monthly, england, 2026-09-01 → annual rent £15,000.00, weekly rent £288.46, weeks 5, maximum £1,442.30
zero rent: zero deposit £0.00, monthly, england, 2026-09-01 → annual rent £0.00, weekly rent £0.00, weeks 5, maximum £0.00
Show the other 9 tests
CaseArgumentsExpected
the first day of the cap, 1 June 2019 £1,000.00, monthly, england, 2019-06-01 → annual rent £12,000.00, weekly rent £230.76, weeks 5, maximum £1,153.84
before 1 June 2019 there is no cap to apply £1,000.00, monthly, england, 2019-05-31 → error: no deposit cap rule for england on 2019-05-31
no data for Scotland £1,000.00, monthly, scotland, 2026-09-01 → error: no deposit cap rule for scotland
rent in euros is refused €1,000.00, monthly, england, 2026-09-01 → error: rent must be in GBP
negative rent is refused -£0.01, monthly, england, 2026-09-01 → error: rent must not be negative
an unknown rent period is refused £1,000.00, fortnightly, england, 2026-09-01 → error: unknown rent period
a malformed date is refused £1,000.00, monthly, england, 1/6/2019 → error: onDate must be an ISO date
a trailing newline is not part of an ISO date £1,000.00, monthly, england, 2026-09-01 → error: onDate must be an ISO date
Arabic-Indic digits are not an ISO date £1,000.00, monthly, england, ٢٠٢٦-٠٩-٠١ → error: onDate must be an ISO date

More from the author

## How it is calculated

The Act defines a week's rent as the annual rent divided by 52, and the government guidance gives the formulae: annual rent is monthly rent × 12 or weekly rent × 52, and weekly rent is (monthly rent × 12) ÷ 52.

- The threshold test is made on the exact annual rent, so £4,166.66 a month (£49,999.92 a year) is five weeks and £4,166.67 (£50,000.04) is six. - The maximum is annual rent × weeks ÷ 52, computed exactly and **rounded down** to the penny once. Rounding the weekly rent first and multiplying by five can land a penny or more away; rounding up would put the deposit a fraction of a penny over the statutory cap. The Act and guidance do not state a rounding rule, so down is the one that can never breach it. - `weeklyRent` is shown for reference, rounded down too.

Pass the total rent for the property: for a joint tenancy the cap applies to the rent all the tenants are jointly liable for, not to each tenant.

## Dates and jurisdictions

The rule is a dated row in `data/deposit-caps.json`. England's cap applies to tenancies granted, renewed or continued on or after 1 June 2019; an earlier date is refused rather than answered. The Renters' Rights Act 2025 amended the Tenant Fees Act but left the deposit cap unchanged (statutory guidance updated 1 May 2026). Wales and Scotland have different regimes and no data here yet; asking for them is an error, not a guess.

## Sources

- Tenant Fees Act 2019, Schedule 1 paragraph 2 (tenancy deposit; "one week's rent" is the annual rent divided by 52): https://www.legislation.gov.uk/ukpga/2019/4/schedule/1 - Ministry of Housing, Communities and Local Government, "Tenant Fees Act 2019: Guidance for landlords and agents" (tenancy deposits: the annual and weekly rent formulae; the cap applies from 1 June 2019): https://assets.publishing.service.gov.uk/media/5f745d308fa8f5189a93d141/Tenant_Fees_Act_2019_-_Guidance_for_landlords_and_agents.pdf - "Tenant Fees Act 2019: statutory guidance for enforcement authorities" (as amended by the Renters' Rights Act 2025): https://www.gov.uk/government/publications/tenant-fees-act-amended-by-the-renters-rights-act-2025/tenant-fees-act-2019-statutory-guidance-for-enforcement-authorities

1.0.1 fixes Python accepting a trailing newline or non-ASCII digits in onDate; adds tests.

## Before you rely on this

**Not professional advice.** This capability calculates property figures from published rules. It is a software component for developers, not legal or financial advice. Rules change and every rate here has an effective date. Check that the dates cover your case. Verify results against the official sources listed above, and have a conveyancer or tax adviser review how you use it, before anyone relies on the output. Provided "as is" under its licence, without warranty.

**Unreviewed.** This capability's implementations agree in every language and pass its published test vectors, which were worked out from the official sources cited. But no qualified conveyancer or tax adviser has yet checked those vectors, or confirmed that the capability covers the cases it claims. Treat it as a draft. Do not use it for real people, money or decisions without your own expert review. Once a qualified reviewer signs off, this notice is replaced with their name, qualification and the date. Each new version needs fresh sign-off.

## Notices

Contains public sector information licensed under the Open Government Licence v3.0 (https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/).

Legislation: Crown copyright and database right.

1.0.2 marks it unreviewed and adds its attribution notices (NOTICE). The code and the tests are unchanged.

Files

PathBytes
NOTICE233
README.md4,187
data/deposit-caps.json265
impl/python.py2,990
impl/rust.rs4,016
impl/typescript.ts2,930
vectors.json6,350