### Set up the development environment Source: https://github.com/ahmedak/defluff/blob/main/CONTRIBUTING.md Clone the repository, create a virtual environment, and install dependencies to begin development. ```bash git clone https://github.com/ahmedak/defluff cd defluff python -m venv .venv && source .venv/bin/activate pip install -e ".[mcp]" pip install pytest pytest ``` -------------------------------- ### Implement CI gate Source: https://github.com/ahmedak/defluff/blob/main/README.md Example GitHub Actions step to lint generated content using specific categories and a custom threshold. ```yaml - name: Check AI-generated content for slop # --category ai-vocab,hedge gates only on the highest-precision categories run: cat generated_output.md | defluff lint --category ai-vocab,hedge --threshold 0.1 ``` -------------------------------- ### Use in reward loops Source: https://github.com/ahmedak/defluff/blob/main/README.md Example of using defluff as a component in a reward mix and comparing two drafts. ```python lex = defluff.load_lexicon() # pin once reward = lambda text: -defluff.detect(text, lexicon=lex).slop_density # unclamped, better gradient delta = defluff.compare(draft_v1, draft_v2, lexicon=lex) # {"score_a": 0.31, "score_b": 0.18, "delta": -0.13, # "improved": [...], "regressed": [...]} # set diff of flagged phrases, not a semantic diff ``` -------------------------------- ### Manage domain packs via CLI Source: https://github.com/ahmedak/defluff/blob/main/src/defluff/data/packs/README.md Commands to list available packs, apply a single pack to a file, or stack multiple packs for linting. ```bash defluff packs # list available packs defluff lint post.md --pack marketing-growth defluff lint post.md --pack marketing-growth,ai-llm # stack several ``` -------------------------------- ### Lint with domain packs Source: https://github.com/ahmedak/defluff/blob/main/README.md Apply pre-defined domain packs to detect specific types of filler. You can stack multiple packs by separating them with commas. ```bash defluff lint post.md --pack marketing-growth defluff lint post.md --pack marketing-growth,ai-llm # stack several ``` -------------------------------- ### CLI reference Source: https://github.com/ahmedak/defluff/blob/main/README.md Command-line interface commands for linting, scoring, and managing lexicons. ```bash defluff lint [FILE] [--json] [--threshold FLOAT] [--category CATS] [--lexicon PATH] [--pack NAMES] [--no-project-overlay] defluff score [FILE] [--pack NAMES] [--no-project-overlay] defluff packs # list bundled domain packs defluff lexicon list [--category CATEGORY] [--scope SCOPE] [--json] defluff lexicon add PATTERN --category CATEGORY [--scope SCOPE] [--weight FLOAT] defluff lexicon rm PATTERN [--scope SCOPE] ``` -------------------------------- ### Reproduce evaluation scores Source: https://github.com/ahmedak/defluff/blob/main/README.md Run the evaluation script to reproduce the precision and recall metrics against the validation dataset. ```bash python eval/score.py eval/validation.jsonl ``` -------------------------------- ### Python Library: defluff.compare Source: https://github.com/ahmedak/defluff/blob/main/README.md Compares two drafts to identify differences in filler usage. ```APIDOC ## Python: defluff.compare(draft_v1, draft_v2, lexicon) ### Description Compares two text drafts and returns a set difference of flagged phrases. ### Parameters - **draft_v1** (string) - First text draft. - **draft_v2** (string) - Second text draft. - **lexicon** (object) - The lexicon object. ### Returns - **result** (object) - Contains `score_a`, `score_b`, `delta`, `improved`, and `regressed` lists. ``` -------------------------------- ### Run tests Source: https://github.com/ahmedak/defluff/blob/main/CONTRIBUTING.md Execute the test suite using pytest to verify changes. ```bash pytest # all tests pytest tests/test_smoke.py # CLI + MCP integration tests pytest tests/test_lexicon.py # unit tests for the lexicon engine ``` -------------------------------- ### Configure pre-commit hook Source: https://github.com/ahmedak/defluff/blob/main/README.md Add this configuration to your .pre-commit-config.yaml to run defluff as a local hook on markdown files. ```yaml # .pre-commit-config.yaml repos: - repo: local hooks: - id: defluff name: defluff slop check entry: defluff lint language: system types: [markdown] ``` -------------------------------- ### Manage lexicon overlays via CLI Source: https://github.com/ahmedak/defluff/blob/main/README.md Customize the lexicon by adding or removing terms at the user or project scope. Project-level changes should be committed to version control. ```bash # "synergy" is slop on this machine defluff lexicon add "synergy" --category corporate --scope user # "leverage" is fine in this repo (finance context) — commit this with the repo defluff lexicon rm "leverage" --scope project git add .defluff/ignore.json && git commit -m "allow 'leverage' in finance context" ``` -------------------------------- ### Python Library: defluff.detect Source: https://github.com/ahmedak/defluff/blob/main/README.md Detects filler density in a given text string. ```APIDOC ## Python: defluff.detect(text, lexicon) ### Description Analyzes text to determine filler density. ### Parameters - **text** (string) - The text to analyze. - **lexicon** (object) - The lexicon object returned by `load_lexicon`. ### Returns - **result** (object) - Contains the `slop_density` property. ``` -------------------------------- ### Python Library: defluff.load_lexicon Source: https://github.com/ahmedak/defluff/blob/main/README.md Loads the lexicon for use in Python scripts. ```APIDOC ## Python: defluff.load_lexicon() ### Description Loads the default lexicon for use in detection or comparison functions. ### Returns - **lexicon** (object) - The loaded lexicon object. ``` -------------------------------- ### Lint with a custom lexicon Source: https://github.com/ahmedak/defluff/blob/main/README.md Use the --lexicon flag to provide a custom file containing phrases to detect. The lexicon file supports comments and list markers. ```bash defluff lint draft.md --lexicon team-slop.md ``` ```markdown # team-slop.md - circle back - low-hanging fruit - boil the ocean paradigm shift ``` -------------------------------- ### Detect rhetorical patterns Source: https://github.com/ahmedak/defluff/blob/main/README.md Use the rhetoric pack to identify sentence shapes like antithesis. The compound mode is enabled by default, while fragment mode requires explicit activation. ```bash defluff lint draft.md # compound antithesis caught by default defluff lint draft.md --pack rhetoric # also catch the punchy "X, not Y" fragment defluff lint draft.md --category rhetoric # gate CI on antithesis alone ``` -------------------------------- ### Detect and score slop with Python API Source: https://github.com/ahmedak/defluff/blob/main/README.md Use the defluff module to detect slop in text, retrieve detailed reports, or perform quick scoring. Load a lexicon to ensure reproducible results across runs. ```python import defluff report = defluff.detect("It is worth noting that we should leverage synergies.") print(report.slop_score) # 0.0 – 1.0 print(report.spans) # flagged phrase locations + categories score = defluff.score(text) # bare float clean = defluff.is_slop(text) # bool at default threshold lex = defluff.load_lexicon() # pin for reproducible runs score = defluff.score(text, lexicon=lex) ``` -------------------------------- ### Suppress domain vocabulary Source: https://github.com/ahmedak/defluff/blob/main/README.md Use the lexicon command to remove specific phrases from the ignore list, then commit the updated configuration file. ```bash defluff lexicon rm "scalable" --scope project defluff lexicon rm "in order to" --scope project git add .defluff/ignore.json && git commit -m "defluff: allow domain vocabulary" ``` -------------------------------- ### Add to custom lexicon category Source: https://github.com/ahmedak/defluff/blob/main/README.md Attempt to add phrases to the custom category via the CLI, noting that the add command is restricted to the five curated categories. ```bash defluff lexicon add --category custom ``` -------------------------------- ### defluff.load_lexicon() Source: https://github.com/ahmedak/defluff/blob/main/README.md Loads the current lexicon, which can be passed to other methods to ensure reproducible results. ```APIDOC ## defluff.load_lexicon() ### Description Loads the resolved lexicon (bundled + overlays) for consistent scoring. ### Response - **lexicon** (object) - The loaded lexicon object. ``` -------------------------------- ### defluff lexicon Source: https://github.com/ahmedak/defluff/blob/main/README.md Manages the lexicon used for filler detection. ```APIDOC ## CLI: defluff lexicon ### Description Commands to list, add, or remove patterns from the lexicon. ### Commands - `defluff lexicon list [--category CATEGORY] [--scope SCOPE] [--json]` - `defluff lexicon add PATTERN --category CATEGORY [--scope SCOPE] [--weight FLOAT]` - `defluff lexicon rm PATTERN [--scope SCOPE]` ``` -------------------------------- ### Suppress false positives Source: https://github.com/ahmedak/defluff/blob/main/README.md Use the lexicon remove command to add domain-specific jargon to an ignore list, preventing it from being flagged as filler. ```bash defluff lexicon rm ``` -------------------------------- ### defluff lint Source: https://github.com/ahmedak/defluff/blob/main/README.md Checks a file for filler density and returns an exit code based on the findings. ```APIDOC ## CLI: defluff lint ### Description Analyzes a file for filler density. Returns exit code 0 for clean, 1 for slop, and 2 for bad input. ### Usage `defluff lint [FILE] [--json] [--threshold FLOAT] [--category CATS] [--lexicon PATH] [--pack NAMES] [--no-project-overlay]` ### Options - **--json** (flag) - Output results in JSON format. - **--threshold** (FLOAT) - Threshold for slop detection. - **--category** (CATS) - Comma-separated categories to count toward exit-code decision. - **--lexicon** (PATH) - Path to a custom lexicon file. - **--pack** (NAMES) - Comma-separated domain packs to use. ``` -------------------------------- ### Add a lexicon entry Source: https://github.com/ahmedak/defluff/blob/main/CONTRIBUTING.md Add new AI-filler phrases to the lexicon by appending a JSON object to src/defluff/data/lexicon-v1.json. ```json {"pattern": "it goes without saying", "category": "hedge", "source": "curated", "added": "YYYY-MM-DD"} ``` -------------------------------- ### defluff.detect(text) Source: https://github.com/ahmedak/defluff/blob/main/README.md Analyzes the provided text and returns a SlopReport object containing the slop score, density, and detailed span information. ```APIDOC ## defluff.detect(text) ### Description Analyzes the input text to identify slop and returns a comprehensive report. ### Parameters - **text** (str) - Required - The text to analyze. ### Response - **SlopReport** (object) - An object containing: - **slop_score** (float) - Clamped [0, 1] score. - **slop_density** (float) - Raw unclamped density. - **spans** (list) - List of flagged phrases and categories. - **categories** (dict) - Per-category density. - **n_words** (int) - Token count. - **low_confidence** (bool) - True if word count is less than 20. - **lexicon_version** (str) - SHA prefix of the resolved lexicon. ``` -------------------------------- ### defluff.is_slop(text) Source: https://github.com/ahmedak/defluff/blob/main/README.md Returns a boolean indicating if the text is considered slop based on the default threshold. ```APIDOC ## defluff.is_slop(text) ### Description Checks if the text exceeds the default slop threshold. ### Parameters - **text** (str) - Required - The text to check. ### Response - **is_slop** (bool) - True if the text is flagged as slop. ``` -------------------------------- ### defluff score Source: https://github.com/ahmedak/defluff/blob/main/README.md Calculates a score for a file based on filler density. ```APIDOC ## CLI: defluff score ### Description Calculates a filler density score for the provided file. ### Usage `defluff score [FILE] [--pack NAMES] [--no-project-overlay]` ``` -------------------------------- ### defluff.score(text, lexicon=None) Source: https://github.com/ahmedak/defluff/blob/main/README.md Returns a float representing the slop score of the provided text, optionally using a specific lexicon. ```APIDOC ## defluff.score(text, lexicon=None) ### Description Calculates the slop score for the given text. ### Parameters - **text** (str) - Required - The text to score. - **lexicon** (object) - Optional - A lexicon object loaded via `load_lexicon()`. ### Response - **score** (float) - The calculated slop score. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.