I definitely agree that any generated rules or configurations need to be reviewed before used. But it still seems like it is worth exploring. I tried giving it a sample YAML-based format that I think is probably similar to what Hazel uses under the hood. then described one of the Hazel rules I created by hand:

Here's the prompt, slightly expanded on the above:
I'd like a YAML configuration in this format to recognize and process my Wells Fargo mortgage statements and rename them to something like "2025-01-14 - Wells Fargo - Mortage Statement - XX6789 ($123,000.00).pdf". The PDF will have the text "WELLS FARGO HOME MORTGAGE" and "Property Location" on the first page. It will also have an account number in format "Account Number: 123456789", and I'd like the last 4 digits of the account number to be used in the filename. It will also have "Unpaid Principal Balance: <balance>" and I'd like that balance to be included in parentheses in the filename.
It produced this, which IMO is a pretty good start. Hazel's GUI features, including ability to preview and debug, would be ideal for reviewing and confirming this actually behaves as expected.
- Code: Select all
rules:
- name: Process Wells Fargo Mortgage Statements
criteria:
- extension: pdf
- content:
contains:
- "WELLS FARGO HOME MORTGAGE"
- "Property Location"
# Extract the statement date (format: MM/DD/YY)
- match:
content: 'Statement date (\d{2})/(\d{2})/(\d{2})'
as-variable: statement_date_raw
# Convert statement date to YYYY-MM-DD format
- set:
variable: statement_date
from-value: '20{statement_date_raw[2]}-{statement_date_raw[0]}-{statement_date_raw[1]}'
# Extract the 9-digit account number
- match:
content: 'Account Number: (\d{9})'
as-variable: account_number
# Extract the unpaid principal balance
- match:
content: 'Unpaid Principal Balance: \$([\d,]+(?:\.\d{2})?)'
as-variable: unpaid_balance
# Extract last 4 digits of account number
- set:
variable: account_last4
from-value: 'XX{account_number[-4:]}'
# Rename and move if everything is found
- rename:
name: '{statement_date} - Wells Fargo - Mortgage Statement - {account_last4} (${unpaid_balance}).pdf'
if: 'statement_date and account_number and unpaid_balance'
- move:
folder: '~/Documents/Wells Fargo/Mortgage Statements/'
if: 'statement_date and account_number and unpaid_balance'
# Move to "Needs Review" if extraction fails
- move:
folder: '~/Documents/Wells Fargo/Needs Review/'
if: 'not (statement_date and account_number and unpaid_balance)'