Help to understand editing with AI

Hello, I ve been trying to edit .md files with AI. I hve used this prompt

You are a metadata and YAML editor for Markdown/text documents.

TASK
Read the current file content.
Detect whether the file already contains YAML front matter.
Then create or update the YAML front matter at the top of the SAME FILE.

GOAL

  1. If YAML already exists:

    • preserve all existing valid fields
    • preserve any extra/custom fields already present
    • complete missing fields
    • improve weak fields when clearly possible
    • keep the same field style already used in the YAML
    • normalize list-like metadata fields so they use the same style as tags
  2. If YAML does not exist:

    • create new YAML front matter using the format below

REQUIRED YAML TEMPLATE

title: Document Title

author: Author Name
creation_date: MMMM D, YYYY
modification_date: TODAY
parent:

children:

tags: [tag1, tag2, tag3, tag4]

aliases: [Document Title, Author Name, Additional Alias]
keywords: [Keyword1, Keyword2, Keyword3, Keyword4]
subject: Short description not more than one line.
cssclasses: [nature, academia]

RULES

  • Apply the YAML directly to the current file, not as a suggestion.
  • Overwrite only the YAML front matter section unless fixing obvious metadata-related formatting issues.
  • Preserve the body text exactly unless YAML insertion/update requires moving the front matter to the top.
  • If current YAML contains extra fields, keep them.
  • Do not delete useful custom fields.
  • Keep field naming and formatting consistent.
  • Tags, aliases, keywords, parent, children, and cssclasses must use a consistent style.
  • Prefer lowercase for tags, aliases, and keywords unless there is a strong reason not to.
  • Remove duplicate values.
  • Remove meaningless tags such as single letters, stop words, broken fragments, punctuation artifacts, isolated symbols, or OCR garbage.
  • Remove malformed entries such as unclosed braces, broken brackets, stray quotes, and dangling separators.
  • Clean spacing and YAML formatting so the result is valid in both DEVONthink and Obsidian.
  • Escape or quote values only when YAML requires it.
  • Infer better title, author, aliases, tags, and keywords from the file content whenever possible.
  • Add more relevant tags, aliases, and keywords if they are strongly supported by the document.
  • subject must be one short line only.
  • modification_date must be today’s date.
  • If creation_date cannot be determined from the file, preserve existing value; otherwise infer from metadata or use the best available document date.
  • Do not invent highly specific facts unless supported by the file content.
  • Output the FULL UPDATED FILE CONTENT only.
  • Do not explain.
  • Do not summarize.
  • Do not wrap the answer in markdown fences.

QUALITY CHECK BEFORE FINALIZING

  • Ensure YAML is valid.

  • Ensure YAML is compatible with both DEVONthink and Obsidian.

  • Ensure front matter begins and ends with —.

  • Ensure the updated file contains exactly one YAML front matter block.

  • Ensure no extra commentary is added.

    Rather than editing the expected fields, it erased all my content in the file. I use ollama with qwen3 14b. Can someone teach me the proper way to do it, I just paste it into chat screen.

Where exactly? Did you enable the option to change properties & contents, see Settings > AI > Chat?

Small chat button. below the toolbar right side. and yes I did checked marked it.

And which model did you use?

It’s useful to ask Claude to debug prompts.

Here’s Claude’s suggestion. Verbatim.

The culprit is this combination:

“Output the FULL UPDATED FILE CONTENT only” + “Apply the YAML directly to the current file” + “Do not explain.”

Here’s the failure chain:

  1. The prompt instructs the model to output the entire file as its response — not just the YAML block.

  2. That output is then written back to the file (overwriting it completely).

  3. Large files will hit output token limits. The model starts writing, gets truncated mid-document, and the file write captures only what was output before cutoff.

  4. Everything after the truncation point is silently gone.

The “Do not explain / do not summarize / no fences” rules make it worse — they strip any protective wrapper that might have signaled to the calling code that something went wrong. The file write sees clean-looking text and proceeds happily.

Secondary risk: The instruction “Overwrite only the YAML front matter section” directly contradicts “Output the FULL UPDATED FILE CONTENT only.” The model has to pick one. Depending on context and model behavior, it may output only the YAML block, which then overwrites the entire file — body included.

The fix is straightforward: don’t ask the model to output the full file. Instead, have it output only the YAML block, and handle the splice programmatically — strip the old front matter, prepend the new one, leave the body untouched. The body never passes through the model at all, so truncation can’t touch it.

My own two cents: when writing prompts describe the desired outcome, and tell the AI where the pitfalls might lie (destructive or irreversible actions, or aspects of your file structure that it probably won’t know about). The AI probably knows more about YAML than you do. Don’t write a YAML manual. The longer the prompt, the more it becomes defensive code — which is a bad sign. Complexity in a prompt usually means the task design itself needs rethinking.

5 Likes

thank you very much