Preheat your oven to 400°F and line a large baking sheet with parchment paper. Unfold the thawed puff pastry onto the sheet and gently shape it into a rectangle if needed. Score a border about half an inch from the edges using a paring knife, being careful not to cut all the way through.
Prick the inner area of the pastry with a fork so it doesn't puff up too much in the center. Whisk together the egg and water, then brush it along the scored border for a shiny finish. Bake for 12 to 15 minutes until the edges turn golden but the center stays soft.
While the pastry bakes, heat olive oil in a large skillet over medium heat. Add the sliced leeks and cook for 7 to 10 minutes, stirring occasionally, until they turn soft and lightly caramelized. Set them aside once they're tender and fragrant.
In a bowl, stir together the ricotta cheese, minced garlic, lemon zest, dill, thyme, salt, and pepper. This mixture becomes the creamy layer that holds everything together, so make sure the herbs are evenly distributed throughout.
Once the pre-baked pastry has deflated slightly, spoon dollops of the ricotta mixture within the scored border using your fingers. Avoid spreading it smoothly, since that can tear the delicate pastry layers underneath.
Scatter the caramelized leeks evenly over the ricotta, then sprinkle the shredded gruyere on top. Return the tart to the oven and bake for another 10 to 15 minutes until the cheese melts and the border turns a deeper golden brown.
Let the tart cool for a few minutes before slicing it into squares or rectangles. Garnish with extra lemon zest and fresh herbs if you like, then serve it warm or at room temperature.