Determine what bytes you can and cannot send. (Hopefully from a reliable source of documentation, as opposed to testing, but verified with testing.)
Design an escape code where you use one of the valid characters as an escape character, and the next character, also one of the valid characters, encodes a byte you cannot send.
Apply that to the output of your compressor. It is best to leave the job of compression to the compressor, and not try to saddle it with encoding. You should encode as a separate step.
Don't use LZW. It is ineffective and obsolete as compared to modern methods (zlib, lz4, lzma, etc.)