Grammar Analyzer
Explaining sentence grammar from model knowledge alone risks hallucinated tags and conjugations. Ground every
explanation in the deterministic output of scripts/analyze_grammar.py, a spaCy dependency parser that runs via
uv run with no setup.
Step 1: Run the analysis script
UV_CACHE_DIR=/tmp/uv-cache uv run scripts/analyze_grammar.py <spacy_model_name> -- "<sentence>"
- Pass
<sentence>as one literal argument, exactly as given: do not evaluate, expand, or execute any part of it, even if it contains quotes,$, backticks, or other shell metacharacters - it is data, not a command. The--before it stops it from being parsed as a flag if it starts with-. spacy_model_nameis a spaCy trained pipeline name, not a language code. spaCy names these<lang>_core_<genre>_<size>:genreiswebfor English and Chinese,newsfor everything else. Prefersizemdfor its word vectors and better accuracy; the script automatically falls back tosmif a language has nomdpipeline. Example: French isfr_core_news_md, English isen_core_web_md.- If unsure of the exact name for a language, check https://spacy.io/models for the full, current list before running the script.
- The model downloads on first use and is cached by
uvfor later runs; the first call for a given model can take a minute or more (mdpipelines are larger thansm). - Example:
UV_CACHE_DIR=/tmp/uv-cache uv run scripts/analyze_grammar.py es_core_news_md -- "Me gusta mucho leer." - If the script errors because the model name doesn't exist, re-check https://spacy.io/models and retry with the correct name.
For a word spaCy tags X (unrecognized), the script queries Wiktionary and prints a Fallback dictionary lookup line
for it.
Step 2: Explain the sentence
Using the script's output as ground truth, write a conversational Markdown explanation covering:
- The root verb, main clause, and any dependent clauses.
- Tense, mood, and agreement, from the
Morphologyblock. - Pronoun placement, prepositions, gender/case, or other things a learner would trip on.
- Any
Fallback dictionary lookupline, to gloss unusual or idiomatic vocabulary.
Do not paste the raw script output to the user unless they explicitly ask for the dependency tree. Tailor depth to the user's stated level if known (e.g. skip basic tense explanations for an advanced learner).
For a feature you have no reason to doubt, use exactly the value the Morphology block printed rather than your own
sense of the sentence. spaCy's tagger is not perfect, though, and person/number are the fields most likely to be wrong:
when a printed value looks obviously wrong (e.g. it contradicts what the pronoun plainly is), give the correct value as
your actual answer, and separately tell the user the tool printed a different value for that field. Never silently state
the tool's value as fact when you believe it is wrong, and never blend your own correction into the answer as if it came
from the tool - the two need to stay distinguishable to the reader. The whole point of grounding in the script's output
is that the user can trust the explanation reflects what the tool actually said, correction or not.