Stoploss triggered but execution failed

Today, for two of my trades in fin nifty, stop loss failed due to limit price breach. It has been twice since this has happened causing me a loss. Can anyone suggest me what changes I need to do in my python code that it takes care of such failures.

If your stop order is at the exchange, then your limit price is too tight. Increase it.
Or detect when order slips and send order again. Neither is perfect. Slippage/loss is a part of trading life.

If you are trading options, then maybe this is also relevant,