Better way to structure and optimise try except statements
Given that there isn't much here to analyse purely based on performance since we don't know what those other function calls do, here are some minor changes:
def data_handler(message, topic):
    try:
        logging.debug(f'Invoked on topic {topic} with message {message}')
        client.publish(topic=topic + '/pass', payload=json.dumps({'state': 'pass'}))
    except Exception as e:
        logging.error(e)
        client.publish(topic=topic + '/fail', payload=json.dumps({'state': 'fail'}))

Both try/catch blocks in your code look identical, and you should have only one endpoint that needs to be communicated with. If you really need both, then there should be a separate function to have this code.
It also seems pretty redundant that you're publishing to a pass and fail endpoint and have a payload that says whether or not it passed or failed. You should know that status based on the endpoint that receives the message.
You can have the payload be more descriptive as well to remove multiple endpoints. Something like {'formatted': true, 'error': ''} is far more informative.
Lastly, you can just pass your one-off variables into this function, like so: data_handler(event, context.topic). If your event really is just a post message and not a posting event object, then that should be clarified somewhere in the code base.