In content creation—whether writing blog posts, research summaries, or personal knowledge notes—the initial drafting phase (First Draft) and the editing phase (Proofreading & Refinement) require entirely distinct cognitive mindsets.
While drafting demands Flow State and uninhibited creativity, proofreading requires meticulous attention to detail: catching typos, verifying tone consistency, and enforcing structural formatting standards.
Many writers fall into the trap of attempting both simultaneously, leading to severe Cognitive Friction and mental fatigue. Implementing Cognitive Automation to handle background editing is an elegant solution that frees mental energy, allowing you to focus entirely on core ideas.
In this guide, we will build a Local AI Article Proofreader Agent using Python and Ollama. This agent automatically scans your Obsidian Vault, corrects grammatical errors, suggests style improvements, and verifies Markdown structure—all processed 100% locally and offline without leaking data to cloud services.
---
### Architecture of the Local Proofreader Agent
Designed with a Local-first & Privacy-centric approach, the agent operates asynchronously from your active note-taking session:
1. Vault File Scanner: A Python script inspects the draft directory (Drafts/) in your Obsidian Vault for Markdown files requested for review (tagged via Frontmatter metadata such as status: proofread-requested).
2. Markdown & Frontmatter Parser: Isolates metadata headers from the body content, ensuring AI editing does not tamper with system tags or configurations.
3. Structured Local LLM Editing: Submits the article body to a local language model (such as qwen2.5 or llama3.2) for a 3-dimensional analysis: Grammar & Spelling, Tone Consistency, and Markdown Structure.
4. Diff & Review Note Generator: Generates a standalone side-by-side review report alongside the original note, summarizing proposed revisions and providing a fully polished version for one-click approval.
---
### Step 1: Environment Setup and Model Selection
Article editing requires a model with strong grammatical reasoning and structural comprehension. Medium-sized models like Qwen 2.5 (7B or 14B) or Llama 3.1 / 3.2 are excellent choices for local processing.
Open your terminal and pull the target model via Ollama:
ollama run qwen2.5:7b
Next, install the required Python libraries for YAML frontmatter parsing and HTTP communication:
pip install python-frontmatter requests PyYAML
---
### Step 2: Writing the Python Proofreader Agent Script
Create a script named proofreader_agent.py on your machine and configure your Vault path and logic:
import os
import glob
import requests
import frontmatter
from datetime import datetime
# Configuration settings
VAULT_DRAFTS_PATH = "/home/linn/ObsidianVault/Drafts"
OLLAMA_API_URL = "http://localhost:11434/api/generate"
MODEL_NAME = "qwen2.5:7b"
PROMPT_TEMPLATE = """You are a Senior Content Editor. Your task is to proofread and refine the following draft:
[Proofreading Guidelines]
1. Identify and correct spelling errors, typos, and grammatical inaccuracies.
2. Refine sentence structures for conciseness, clarity, and tone consistency (Tech-savvy, Professional, Actionable).
3. Verify Markdown structure (proper H2/H3 headers, bold emphasis on key terms, clean list formatting).
4. Do not alter core facts, authorial intent, or original meaning.
[Raw Draft Content]
{article_text}
[Required Output Format]
Respond in clean Markdown with 2 distinct sections:
### 1. Suggested Revisions
- List of corrected spelling/grammar errors
- List of tone and structural sentence adjustments
---
### 2. Polished Version
(Place the full, fully polished article content here)
"""
def process_draft_file(filepath):
print(f"📄 Reading file: {filepath}")
with open(filepath, 'r', encoding='utf-8') as f:
post = frontmatter.load(f)
# Verify if review is requested
if post.metadata.get('status') != 'proofread-requested':
return
print("🤖 Submitting content to Local LLM for editing...")
prompt = PROMPT_TEMPLATE.format(article_text=post.content)
payload = {
"model": MODEL_NAME,
"prompt": prompt,
"stream": False
}
try:
response = requests.post(OLLAMA_API_URL, json=payload)
response.raise_for_status()
result = response.json().get('response', '')
# Save output to a dedicated review note
base_name = os.path.basename(filepath)
filename_without_ext = os.path.splitext(base_name)[0]
review_filename = f"{filename_without_ext}-review.md"
review_path = os.path.join(os.path.dirname(filepath), review_filename)
review_content = f"""---
title: "Review: {post.metadata.get('title', filename_without_ext)}"
date: "{datetime.now().strftime('%Y-%m-%d')}"
type: "proofread-report"
original_file: "{base_name}"
---
# Article Review Report: {post.metadata.get('title', filename_without_ext)}
{result}
"""
with open(review_path, 'w', encoding='utf-8') as f_out:
f_out.write(review_content)
print(f"✅ Proofreading report generated: {review_path}")
# Update original file status
post.metadata['status'] = 'proofread-completed'
with open(filepath, 'w', encoding='utf-8') as f_orig:
f_orig.write(frontmatter.dumps(post))
except Exception as e:
print(f"❌ Processing error: {e}")
def main():
markdown_files = glob.glob(os.path.join(VAULT_DRAFTS_PATH, "*.md"))
for file_path in markdown_files:
if not file_path.endswith("-review.md"):
process_draft_file(file_path)
if __name__ == "__main__":
main()
---
### Step 3: Integrating into your Obsidian Workflow
1. Create a new draft in your Obsidian Drafts/ folder, such as my-new-post.md.
2. Add the Frontmatter tag status: proofread-requested at the top of the note:
---
title: "Time Management for Software Engineers"
status: "proofread-requested"
---
Here is a quick first draft with some typos and rough sentence flows...
3. Run the Python script in your terminal:
python proofreader_agent.py
4. The agent creates my-new-post-review.md automatically, displaying line-by-line revisions alongside the polished version while updating the original note's status to proofread-completed.
---
### Conclusion and Benefits of Cognitive Automation
Automating proofreading with a Local AI Proofreader Agent unlocks three fundamental advantages:
- Sustained Flow State: Separates the creative brain from the critical editing brain, eliminating distraction during drafting.
- 100% Data Privacy: Your private thoughts and unpublished drafts in your Second Brain remain strictly local.
- Custom Style Enforcement: You can easily customize the prompt template to enforce your personal or brand style guide.
Integrating this type of Cognitive Automation transforms your Second Brain from a passive repository into an active, intelligent drafting partner.