I would use the inspect/2
function on each of your args, it will wrap the string and escape embedded quotes.
EDIT: It will escape double quotes, not single. So not a perfect solution for one of your use cases.
Maybe:
value
|> inspect
|> String.replace("'", "\\'")
Will do the trick?