For example I consider a heat equation that I want to solve numerically : $$u_t=u_{xx},$$ In order to have a uniqueness on a computational bounded domain I have to have boundary condition specified for both $x_{min}$ and $x_{max}$. Ideally I can specify the value of the function, if it is not known I can specify the value of the derivative. However, even if I use the exact solution to specify value of the derivative I noticed that the error at the boundaries is larger than in the middle of the grid. It might be a bug in the code or a fundamental error that I don't get.
Therefore, my question is: does Neumann boundary condition maintains uniqueness of a solution or it is only valid for Dirichlet? And when I can safely use gradient value on the boundary compare to the value of the function itself? Sometimes, I have no idea about the value of the function on the boundary, however, it is more natural to set the boundary values though the derivatives.