Guilds were established to prevent outsiders to do same type of work as they do.
They monopolized their services and sold permits.
They regulated markets, prices and education.
They punished violations of their rules (which they unilaterally imposed) by fees, violence and stigmatization. Sometimes by exiling which was pretty much death sentence.