In recent years, two-photon lithography (TPL) has emerged as a practical and promising micro- and nano-fabrication technique for a wide range of applications. Numerous studies have reported improving the process control and printed feature size of TPL, including by incorporating some degree of hardware improvements, which may be prohibitive for commercial systems. However, the geometric accuracy of TPL-fabricated 3D structures has not been well understood. In this study, a general machine-learning-based framework is presented to quantitatively model and improve the geometric compliance in TPL. The framework quantifies the spatial variation in geometric compliance of fabricated 3D structures, and then designs compensation strategies to improve the geometric compliance. Two experimental case studies, one at the microscale and the other at the nanoscale, are presented to demonstrate the effectiveness of the framework. It is revealed for the first time that systematic geometric errors exist in TPL-fabricated structures and such errors exhibit a strong spatial correlation. The produced compensation strategies reduce the average errors in key geometric features at the microscale and nanoscale by up to 79.7% and 47.4%, respectively. The case studies demonstrate that the proposed framework can effectively improve the geometric compliance without introducing any modifications to the hardware or process parameters, thereby facilitating more widespread adoption.