I think the dnd rules are a little vague on this, perhaps intentionally. It does clearly state you fail a pickpocket if the target passes a perception check, but that doesnt mean every undetected attempt passes nor that you cannot steal when someone notices.