Given a form
F = ufl.inner(grad(u), grad(v)) * ufl.dx - ufl.inner(f, v)*ufl.dx
add a new constraint to boundary nodes only, say F_v = u^2*v * ufl.ds - g*v* ufl.ds, which would remove all other contributions from these rows.
Should be possible to construct by setting the correct strong bcs in the matrix/vector assembly (homogenous/alpha=0.0)
then assemble the F_v into the vector/matrix.