Stopping certain data from ever leaving your Mac?
Practically, no
Practically speaking, it is not possible to ensure a particular string never leaves your computer via a network connection.
You can however monitor and manage who your Mac communicates with, see Is there a good tool for monitoring network activity on Mac OS X?
Why?
Applications and processes running on your computer could encode or encrypt the string in a manner that can not be easily detected, and that encoded form could then be sent over the network.
Network traffic is encrypted
On a recent installation of macOS, there are vanishingly small amounts of plain network data for you to filter and monitor.
Modern network protocols encrypt the data being sent. Protocols that send data in a plain unprotected form are being actively removed or relegated to exceptions rather than common use.
Even the widely deployed Hyper Text Transfer Protocol (HTTP) is rapidly being superseded by the encrypted replacement HTTPS, as browser makers raise awarness with their users.
Theoretically, yes
In theory, it feels possible. A solution would have to inspect every network connection and be able to decrypt every encrypted connection. This might even be attempted in some secrecy focused organisations.
For a home or professional user, such a task unlikely to be achievable while retaining a functioning useful computer.
Man-in-the-Middle Attack
I am assuming you do not want to Man-in-the-Middle (MITM) attack your own computer's traffic; this itself is complex, error prone, and defeats the benefits of encryption.
I am also aware of an increasing number of services that pin their TLS certificates to thwart such attacks.