I feel like most of the problems with AI using a library is how we mix code and implementation. C, C++ got it right (even if by accident) with separating specification from implementation.
Instead of lamenting the design trend of not maintaining this split, for my own code I wrote a utility to extract specifications from my existing code.