Localized code modification with generative models

How to prevent unnecessary whole-function rewriting while preserving enough freedom for a generative model to make the requested code change.