In most of the cases, we overrate or underrate the performance and if it is the latter, we are sometimes held accountable that we have jeopardized their opportunities.
Personally, I think that a good approach here is not to write a recommendation letter unless you are comfortable showing it to the student. Unless there is some strict restriction to the contrary on the process, you can show the student the letter you have written and then let them decide whether they still want to use you as a reference. This gives you the freedom to openly disclose negative aspects of the student's abilities, and leave it up to the student whether they still wish to use you as a reference. This also has the secondary advantage that your student is able to see your assessment of their abilities, and if you have a negative view of some aspect of their skills/abilities/attitude, this is not a secret to them. All you can reasonably be expected to do is to make an assessment of the quality of the student to the best of your abilities; it is up to the student to decide whether you are a good person from whom to solicit a recommendation. Blaming you for jeopardising their opportunities is shooting the messenger.
This idea relates to a selection problem that comes from the fact that some academics refuse to write a letter if they would say anything negative about the student. Several of the comments to your question recommend this approach, and as a result, it is sometimes expected that all letters of recommendation will be unambiguously positive. That is, it is expected that a good student will be able to find a given number of referees that can be unambiguously positive about their abilities. Whatever you think of that filtering mechanism, in my view it is generally a good idea if the student knows what their professors think of them, and this is best accomplished simply by showing them the letter you have written. For my part, in cases where I have asked my professors for recommendations for an academic program or job, most of my professors have sent me a copy of their recommendation without me asking them to do so. (Often they have written a recommendation by email, and BCCed me into the email, even if the process says that applicants do not get to see the recommendations.)
Another related problem here is when academics (erroneously) think it is their duty to over-rate their students in order to be generous in their recommendation letters. If enough academics do this then it becomes "normal" and other academics feel the need to follow suit so that their own unbiased ratings do not disadvantage their students relative to the prevailing norm. So, the first rule for recommendation letters should be to give the most objective assessment of the student you can, and don't intentionally over-rate or under-rate the student. In particular, don't feel the need to be generous to the student in order to assist them with getting a place in graduate school. The second rule is that nothing you write in your letter should come as a surprise to the student; either you have showed them the letter, or they are otherwise aware of your views on their strengths and weaknesses.
Is there a way out to have a balanced approach while writing recommendations?
As to the substance of how to avoid over-rating or under-rating the student, I would recommend that you start by setting out basic factual information about the marks the student got in your courses, and how that compared to the cohort. This will lead you naturally to the ability to say that the student was "in the top X% of students taking my such-and-such course" (best to compare over several years if possible), which gives some basic quantification of accomplishment in your courses. By placing the student's mark in the context of other outcomes in their cohort, you go beyond reiterating information that is already in their transcript, and this also gives you a "jumping off" point for further discussion of the strengths and weaknesses of the student.
To progress from this point, it is usual to give some information on the existing skills of the student, the speed at which they are able to learn new skills, their ability to take a task from initiation to completion, and how much guidance and encouragement they require to do this. It is common to also comment on what it is like to work with the student; i.e., their general attitude, and whether there are any difficulties in dealing with them. For students of sufficient quality to be applying for grad-school or post-doc positions, they are usually good on all fronts, but if there is a weakness you should feel free to disclose this. If you want to try to be balanced to an individual student, imagine that you have to write and submit letters for all your students, and the relative quality of each student will emerge by comparison of all these letters. Thus, if you over-rate one student, then ceteris paribus, that detracts from the recommendations to the other students. Try to be fair to all of your students by making sure you are objective in your assessment of each individual.
Finally, one important thing to ensure that you do not over-rate or under-rate the student is to avoid commenting on things where you do not have enough information. Thus, if a student was just one person in a sea of faces in a large lecture course, you might not have any idea of their abilities beyond their performance in the course. In these cases you should stick to what you know, and don't speculate on what you don't know.
As a typical example, if the student is an extremely good experimentalist but is not so good, probably poor, in visualization of data, then what should be our approach if we have to address this attribute without being too harsh or too mild.
I would recommend you frame your assessment of the student in terms of your view on their potential for research in the program/position to which they are applying. For any given skill, you can give an assessment of the present ability of the student, and also an assessment of whether the student has shown the required qualities to develop this skill to a higher level. So if the student is poor in visualization of data, you would need to make an assessment of whether the student will be able to improve this. Assuming your assessment is positive, you could then say something to the effect that the student has highly-developed skills as an experimentalist, but they need to develop their data visualization skills further (and you think they can do this).
This is another reason why it is generally a good idea to allow the student to read your letter. If you inform the student of this drawback in their skills, you can also let them know that if they are able to develop that skill further, then you will be able to write them a more positive letter in the future. This might spur the student to take an additional course on data visualization, or do some extra practice, and then come and show you that they can now do it really well. For any identified areas of weakness, the student can see this as an opportunity to "plug the gap" and then come back to you for an even better reference at a future point.