# formbrake `formbrake` is a small Python library and CLI that decides when a browser-agent click, form fill, or action plan should pause for human approval. Browser agents are moving from demos into logged-in sessions: they can fill forms, send messages, check out carts, manage repositories, and trigger production workflows. The risky part is often not navigation itself, but the final action: submit, pay, delete, publish, invite, upload, or type a secret. `formbrake` makes that boundary explicit with deterministic local checks. It does not run a browser, call an LLM, or send data to a service. It inspects action JSON or HTML snapshots and returns approval signals that an agent loop, Playwright wrapper, CI job, or MCP tool can use before acting. ## Why This Exists AI browser automation is becoming a normal developer primitive, while human-in-the-loop controls remain uneven across frameworks. Full browser runtimes increasingly ship guardrails, but many teams still have a custom Playwright, Puppeteer, or MCP action loop that needs one narrow check: > Is this next browser action too sensitive to run unattended? `formbrake` focuses on that small decision. It is meant to sit before an action executor, not replace a browser runtime, test framework, policy engine, or security scanner. ## Install The project is not published to PyPI yet. Install from GitHub after the repository is available: ```sh python -m pip install "git+https://github.com/mikebfox/formbrake.git" ``` For local development from a checkout: ```sh python -m pip install -e . ``` Requires Python 3.10 or newer. ## CLI Usage Assess an action plan: ```sh formbrake plan.json ``` Use JSON output for an agent loop: ```sh formbrake plan.json --format json --fail-on high ``` Gate a page snapshot and allow only expected destinations: ```sh formbrake checkout.html --mode html --allow-domain example.com ``` Read from stdin: ```sh cat action.json | formbrake --format json ``` Example input: ```json { "steps": [ { "action": "click", "text": "Pay now", "url": "https://billing.example.com/checkout" } ] } ``` Example output: ```text formbrake: high - 1 approval signal(s) HIGH FB002 at steps[0]: High-impact browser action needs human approval. evidence: pay fix: Pause before executing transactional, destructive, or external-message actions. ``` ## Library Usage ```python from formbrake import BrakeOptions, assess_action, should_fail action = { "action": "fill", "fields": { "api_key": {"type": "password"}, "message": "Deploy production" } } assessment = assess_action( action, BrakeOptions(allowed_domains=("example.com",)) ) if should_fail(assessment, "medium"): request_human_approval(assessment.to_dict()) ``` Values typed into fields are not echoed in findings. Field names and metadata are enough for the approval decision. ## API ### `assess_action(action, options=None)` Assesses one loose browser action dictionary. Common keys such as `action`, `type`, `text`, `selector`, `target`, `url`, and `fields` are inspected. ### `assess_plan(plan, options=None)` Assesses a list of actions or an object containing `actions`, `steps`, or `plan`. ### `assess_html(html, options=None)` Parses HTML forms, fields, and buttons with Python's standard `html.parser`. ### `BrakeOptions` Options: - `allowed_domains`: optional tuple of allowed target domains. - `sensitive_terms`: override field terms that require approval. - `high_impact_terms`: override click or submit words that require approval. ### `should_fail(assessment, threshold="medium")` Returns `True` when the assessment severity is at or above `low`, `medium`, or `high`. ### `format_text_report(assessment)` Formats a terminal report. ## Checks - `FB000`: no browser actions found in the input. - `FB001`: sensitive field interaction, such as credentials, tokens, payment data, or identity data. - `FB002`: high-impact click or submit text, such as pay, delete, publish, invite, transfer, merge, or approve. - `FB003`: non-HTTPS target URL. - `FB004`: target domain outside the configured allowlist. - `FB005`: browser script execution action. - `FB006`: hidden bidirectional Unicode control character. - `FB007`: file upload field. ## Design Notes `formbrake` is deterministic by design. It uses string and HTML structure checks instead of model scoring, because the approval gate should be predictable and easy to test. The project intentionally has a narrow scope: - It does not claim a page is safe. - It does not inspect JavaScript behavior. - It does not replace browser sandboxing or network controls. - It does not send form values to logs or services. Use it as a cheap brake before executing the sensitive part of an otherwise normal browser automation flow. ## Development ```sh python -m pip install -e . python -m compileall src python -m unittest discover -s tests -v python -m formbrake --help ``` ## License MIT