As per the API documentation https://www.twilio.com/docs/sendgrid/for-developers/sending-email/segmentation-query-language#contains, CONTAINS function is mainly for querying on arrays(not a string function). One way to query for a subject line would be to use the LIKE operator(encoded).