A two-dimensional (2D) photonic crystal (PC) structure is proposed in this paper that can measure (sense) the nonlinear coefficient (NC) of a fluid. The sensor structure is designed on a silicon slab of refractive index (RI) of \(3.46\) and composed of a L3 cavity created between two (BUS and DROP) defect waveguides. The photonic band gap (PBG) of the proposed structure is analysed using plane wave expansion (PWE) method and electromagnetic wave propagation through it is evaluated using the 2D-finite difference time-domain (2D-FDTD) method. The performance of the L3 cavity is optimized by properly setting the radius and number of the adjacent rods located on either side of the L3 cavity. At the resonance wavelength of \(1554{\text{nm}}\) , the proposed structure with optimized parameters shows a high-quality (Q)-factor (of \(5180\) ), high RI sensitivity (of \(450{\text{nm}}/{\text{RIU}}\) ), low detection limit (DL) (of \(6.6*{10}^{-5}{\text{RIU}}\) ), and high figure of merit (FOM) (of \(1500{\mathrm{ RIU}}^{-1})\) . Considering the example of brilliant green dye (BGD) it is shown that the proposed sensor can measure the NC of fluids quite accurately.