How to Fix SQL Server Error 10521 (Msg 10521)
You see sql server error 10521 when a plan guide call leaves a needed input set to null. To fix it, pass the required value that matches your chosen plan guide type. Plan guides help database teams tune query execution plans without rewriting app queries. When a deployment script leaves out a needed input value, the database blocks the change. The engine throws a severity 16 error so the bad guide cannot save. Severity 16 errors point to user input mistakes that engineers can fix right away.
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You see sql server error 10521 when a plan guide call leaves a needed input set to null. To fix it, pass the required value that matches your chosen plan guide type.
Plan guides help database teams tune query execution plans without rewriting app queries. When a deployment script leaves out a needed input value, the database blocks the change. The engine throws a severity 16 error so the bad guide cannot save. Severity 16 errors point to user input mistakes that engineers can fix right away.
Why sql server error 10521 happens in the database engine
The database engine checks every input before it saves a new plan guide. Msg 10521 states that the engine cannot create the named plan guide. It triggers because you picked a specific guide type but left a required input as null. The chosen plan guide type requires that missing value to work.
Plan guides come in different types for stored procedures, standalone queries, or query templates. Each type needs its own set of matching inputs to tell the engine where to apply hints. For example, an object guide needs the name of a stored procedure or function. A query guide needs the exact text of the batch or statement.
This failure often happens when teams copy deployment scripts across test and live servers. A variable that holds the module name or batch text might fail to load. If that variable stays null, the system stops the command right away. It returns sql server error 10521 and rolls back the plan guide step. Your live queries keep running with their old plans until you fix the script.
How to check and fix the error safely in production
Start by reading the full error text in your query output log. The message shows three key details in quotes. First, it gives the name of the plan guide that failed. Second, it shows the type value you passed to the system. Third, it names the exact input that arrived as null.
Open the script that tried to create the plan guide. Check the input named in the error message and see why it is null. If you use variables to pass text, check that every variable has a value set. Make sure you did not pick the wrong guide type for your target query. Once the inputs match the required type, run the script in a test database first.
Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
How to manage database roles for plan guide changes
Fixing query plans in production requires strong access controls. Teams often give out broad roles when an urgent query slowdown happens. For example, the db_owner fixed role can run all setup and maintenance tasks. Still, a db_owner member can also drop the whole database in SQL Server.
Keep routine debug access separate from admin write access. A database user is the identity of a login when it connects to a database. For people who need access to many databases on an instance, a login in master is common. For access to one or a few databases, a contained database user is an option. An admin must first enable contained databases on the server and the database.
Give engineers read access through the db_datareader fixed role during triage. Members of db_datareader can read all data from all user tables and views. You cannot change the permissions assigned to fixed database roles. Pair read roles with data masking to rewrite emails, phone numbers, card numbers, and national IDs in results. When the fix for sql server error 10521 is ready, run it through an approved change flow.
Govern SQL Server queries and responses in flight
Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev sits inline in the TDS wire protocol next to SQL Server as a sidecar for your SQL Server. On every production batch from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for approval.
With hoop.dev guardrails and hoop.dev data masking, banned statements are refused or held for review, matched sensitive fields in supported result columns are masked in memory, and each decision is logged. Check out the code on GitHub.
Frequently asked questions
What does severity 16 mean for sql server error 10521?
Severity 16 means the error came from a mistake in the user request. The database engine stays healthy and online, and you can fix the issue by updating your script inputs.
How do I know which input caused Msg 10521?
Read the exact text of the error message in your query tool. The message fills in the plan guide name, the chosen type, and the specific input that was null.
Does Msg 10521 stop running queries in my database?
No, this error only stops the new plan guide from saving. Existing queries keep running with their current execution plans until you run the corrected command.
Related guides
In this post