Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

You can build a small cognitive-distortion text detector in Python with regular expressions and a dataclass: it checks for phrases associated with ten categories and returns a reflection prompt when it finds a match. It is a rule-based programming demonstration, not a clinical assessment. A matching word such as “always” or “should” is only a clue for reflection; it does not establish that a thought is distorted.

The October 1, 2026, DEV Community tutorial describes the approach as: “No ML model. No API key. Just pattern matching on the linguistic markers that therapists look for.” Read the tutorial.

What the Python detector does

The tutorial defines a Distortion dataclass to hold four pieces of information for each category: its name, a description, a list of regular-expression patterns, and an intervention prompt. Its detection function lowercases the supplied text, checks the patterns for each category, and returns a result when any pattern in that category matches.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Each result includes the category name and description, the matched phrase or phrases, and a suggested prompt intended to help the reader reflect. The detector returns at most one result per category; multiple matching patterns for the same category do not create separate category results.

The tutorial says the detector itself needs neither a machine-learning model nor an API key. It does not specify a supported Python-version range or a tested runtime environment, so check your own environment before relying on the code unchanged.

Which ten categories does it check?

The tutorial represents each category with example linguistic markers. These are the rules the program searches for, not proof that a sentence reflects a particular thinking pattern.

Category Example markers in the tutorial
All-or-Nothing Thinking “always,” “never,” “completely,” “totally”
Overgeneralization “every time,” “always,” “never again”
Mental Filter “only,” “just,” “nothing but”
Disqualifying Positive “doesn’t count,” “doesn’t matter,” “just being nice”
Mind Reading “they think,” “everyone knows,” “people are thinking”
Fortune Telling “I’ll never,” “going to fail,” “will never”
Magnification “terrible,” “awful,” “disaster,” “catastrophe,” “worst”
Emotional Reasoning An “I feel … so/therefore … must/am/means” style pattern
Should Statements “should,” “must,” “have to,” “ought to”
Labeling Examples such as “I’m a …,” “I am a …,” “he is a …,” and “she is a …”

What happens with the tutorial’s sample thought?

The tutorial tests this sentence: “I always mess up. They think I’m a failure. I should just quit.” Its example output reports four category matches:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • All-or-Nothing Thinking: the rule finds “always.” Its prompt encourages looking for middle ground.
  • Mind Reading: “They think” matches the pattern. Its prompt asks the reader to examine the evidence for assumptions about other people.
  • Should Statements: “should” matches the rule. Its prompt invites reconsidering rigid “should” language.
  • Labeling: “I’m a failure” matches the example pattern. Its prompt suggests describing behavior instead of defining a person by a label.

These are the tutorial’s rule-based results for one sample sentence, not a clinical assessment or a finding about the person who wrote it.

Where regex matching can mislead

A phrase can match a rule without expressing the category the rule is meant to flag. “Always” may describe a literal routine; “should” may appear in ordinary advice; and “only” may be used without filtering out positive evidence. Lowercasing makes matching less sensitive to capitalization, but it does not give the function an understanding of context.

The tutorial does not report tests for negation, sarcasm, context, or languages beyond the patterns shown. It also supplies no test dataset, clinical validation, precision, recall, sensitivity, specificity, error rate, or outcome measurement. That means the article does not establish how reliably the rules distinguish distortions from ordinary language; it does not establish that no relevant research exists elsewhere.

  • Use a match as a possible reflection prompt, not a label for a person or a diagnosis.
  • Review the sentence and surrounding context yourself rather than treating a match as a conclusion.
  • Do not present this demonstration as a substitute for a therapist or other qualified professional.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How to use the tutorial as a programming exercise

The project is useful for learning how to organize rule-based text matching: store related data in a dataclass, loop through categories and pattern lists, and return structured results for matches. Keep the program’s output framed as suggestions for reflection, and make it clear to anyone using it that the rules can produce false positives and miss relevant language.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The tutorial also mentions a broader toolkit with an API, browser tools, PDF workbooks, and a Python package. Its author reports 226 repository clones, 2 stars, and 0 paid supporters as a build-in-public snapshot in the October 1, 2026, article. Those are self-reported project-engagement figures, not independent measurements or evidence of clinical effectiveness. The article does not establish the current availability of the toolkit’s services.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.