You don't really need to "stick to" anything. Chord tones in a melody will always bring the melody into focus with the harmonic background, while non-chord tones may function as passing tones as you move from one chord tone to another, as added color tones, as deliberate dissonances that add tensions and later resolve to consonances (usually chord tones), or even non-chord tones that deliberately avoid both chord tones and the even the underlying key.
Learning how to use all these possibilities is a big part of learning to compose music.