Arrow pointing off grid when I wrote code that prohibits that.

hi there, im having an issue with my game. I've written code that prohibits the arrows to be placed pointing off the grid when placed on the perimeter of the grid. it works for the most part, but sometimes if i place an arrow pointing off grid but further in the center of the grid then place one on the perimeter, the limit is not respected. I can see that within the output that the name of the selected arrow changes to something not in my tile atlas constants(adds a B between the color and direction). i think this is the issue, but not sure where it comes from.

here is the relevant code (or the section of code i believe to be relevant)

func update_selected_tile(direction: String) -> void:
    if direction.ends_with("BLUE") or direction.ends_with("RED"):
        selected_tile = direction
    else:
        selected_tile = direction + ("RED" if current_player == 1 else "BLUE")
    print("Selected tile: ", selected_tile)


func is_pointing_off_grid(target_coords: Vector2i) -> bool:
var directions = {
"RIGHT": Vector2i(1, 0),
"UP": Vector2i(0, -1),
"LEFT": Vector2i(-1, 0),
"DOWN": Vector2i(0, 1)
}
var direction = selected_tile.substr(0, selected_tile.length() - 3)
if direction in directions:
var check_coords = target_coords + directions[direction]
if not is_valid_tile_position(check_coords):
return true
return false

https://preview.redd.it/xlyvynbrwsde1.png?width=980&format=png&auto=webp&s=1ee62622c2448605a05f2a3287ad38c8c417bf52