Section 1670.5 gives a court three options rather than one. Subdivision (a) provides that if the court finds, as a matter of law, that the contract or any clause of it was unconscionable at the time it was made, the court may refuse to enforce the contract, or enforce the remainder without the unconscionable clause, or so limit the application of the clause as to avoid any unconscionable result. That graduated remedy is why an unconscionability finding does not usually destroy the agreement: the ordinary outcome is that the offending clause is severed or read down.
Two phrases fix the test. "As a matter of law" makes it a question for the judge, not the jury. "At the time it was made" makes it a question about formation, not about how things turned out: a bargain that became a bad one is not unconscionable, and a clause that has never yet been invoked can be. California courts apply the doctrine as requiring both procedural unconscionability — oppression or surprise in how the contract came about, typically a form contract presented on a take-it-or-leave-it basis — and substantive unconscionability — terms that are overly harsh or one-sided — on a sliding scale, so a great deal of one reduces how much of the other is needed.
Subdivision (b) is procedural and easy to overlook: where it is claimed or appears to the court that a contract or clause may be unconscionable, the parties must be afforded a reasonable opportunity to present evidence as to its commercial setting, purpose and effect. The doctrine is therefore decided on evidence about how the term came to be there and what it does, not on the bare words. Section 1668 is the neighbouring provision for clauses that exempt a party from responsibility for fraud, willful injury or violation of law. Whether a term in your contract is vulnerable is a question to take to a lawyer with the whole document.