Invental/Review lessons/Code that silently does the wrong thing

Code that silently does the wrong thing

An LLM that rewrites a file must see all of it

When a model is asked to output a whole file that you then write to disk, it must have seen the whole file; truncating the input silently turns an “edit” into a deletion.

01 · Before and afterThe pattern

JS
// before: page clipped to fit the prompt, model output overwrites the file
prompt.push(block('existing-page', page.slice(0, 30_000)));

// after: refuse rather than truncate
if (page.length > MAX_CHARS) throw new Error(`${path}: too large to rewrite safely`);
prompt.push(block('existing-page', page));

02 · Run it on your appThe check

In any job where an LLM rewrites a file, can the input ever be shorter than the file it replaces?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.