You can implement a watermarking method by subtly embedding token patterns or syntactic cues in the output text for later verification.
Here is the code snippet below:

In the above code we are using the following key points:
-
A basic token-based embedding strategy that injects characters from a watermark key.
-
Syntactic insertion at fixed intervals to subtly embed a pattern.
-
Simple randomness to reduce detectability while maintaining verifiability.
Hence, watermarking LLM outputs enables post-generation validation for authenticity without disrupting naturalness.