Safe caravan entrance, works every time:
Surface level (W = wall, ^ = ramp up, v = ramp down, B = the secured part of a bridge that raises, ( or ) = the part of the bridge that isn't on the ground because you raised the bridge to make it an impassable wall, _ = the unsecured part of a lowered bridge that raises, or just a bridge)
...*****...
...* *...
...DEPOT...
...* *...
...*****...
...........
WWWW^^^WWWW
...WWWWW...
...........
...........
...........
...........
.....W.....
...........
...........
...........
...........
...WWWWW...
...W^^^W...
...W...W...
...W...W...
..(B...B)...
..(B...B)...
..(B...B)...
..(B...B)...
..(B...B)...
..(B...B)...
<map edge>
Surface level +1
...,,,,,...
..., ,...
...depot...
..., ,...
...WWWWW...
...W W...
WWWWvvvWWWW
...WBBBW...
...W___W...
...W___W...
...W___W...
...W___W...
...WBBBW...
...W___W...
...W___W...
...W___W...
...W___W...
...W___W...
...WvvvW...
...W W...
...WWWWW...
..._____...
..._____...
..._____...
..._____...
..._____...
..._____...
<map edge>
Surface level +2
(put a roof on it)
Lowdown:
Caravans have access to the depot from the map edge in only one place, and so will always show up there. Basically, make their path and close off the end of it not with walls (which cannot be built near the map edge) but with raised bridges for walls and a bridge on top for a roof. I have them going over a raised bridge so that in case of invaders coming through this passage (it's super rare, but possible) the drawbridges can be pulled (I have 2 because security should be redundant), sealing in that entrance and dropping them back to the exterior. Now, you don't have to raise this portion like I do, you can just make the bridge on the ground or subterranean. However I didn't do that because if you lower the bridge it will destroy every person and thing under it. Yeah, destroying invaders is great, but I don't want to run the risk if it being a caravan (or militia member, or guard animal, so I'd rather drop them into the exterior where they can be dealt with some other way. Make sure to pen an animal at the map edge inside the passage to see kobolds and such. I like any large animal for this - it can be a ram or cow if you want to use a grazer, just make sure to dig out the soil immediately under the surface where he's penned so trees won't grow - but otherwise something like a bear or war dog on a paved road works great. I find it's not helpful to chain them in because if they become useful (enemies) you don't want them immobile.