A system for rod bending for use in robotic spinal surgery, enabling the correct bending of a fusion rod to match the shape required to accurately pass through the heads of the pedicle screws. The system uses data generated by information provided to the robot by the surgeon's preoperative plan, optionally augmented by feedback from the robot control system of deviations encountered intraoperatively. Such deviations could occur, for example, when the surgeon decides intraoperatively on a different trajectory or even to skip screws on one vertebra, in which case, the robot will be commanded to perform the alternative procedure, with commensurate instructions relayed to the control system of the rod-bending machine. The system is also able to thin down the rod at predetermined locations along its length, adapted to be at selected intervertebral locations, for maintaining limited flexibility between vertebrae, instead of fixating them.