{"record":{"id":"ce8998ce8509acb2","repo":"dotnet/machinelearning","slug":"only-one-of-input-ids-or-inputs-embeds-may-be-set-ce8998","errorCode":null,"errorMessage":"Only one of input_ids or inputs_embeds may be set","messagePattern":"Only one of input_ids or inputs_embeds may be set","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.ML.GenAI.Mistral/MistralModel.cs","lineNumber":70,"sourceCode":"#pragma warning restore MSML_GeneralName // This name should be PascalCased\n    {\n        if (input.OverrideCache is not null)\n        {\n            this._cache = input.OverrideCache;\n        }\n\n        var outputAttentions = input.OutputAttentions;\n        var outputHiddenStates = input.OutputHiddenStates;\n        var attentionMask = input.AttentionMask;\n        Device device;\n        var inputIds = input.InputIds;\n        var positionIds = input.PositionIds;\n        var inputsEmbeds = input.InputEmbeddings;\n        int batchSize;\n        int seqLength;\n        if (inputIds is not null && inputsEmbeds is not null)\n        {\n            throw new ArgumentException(\"Only one of input_ids or inputs_embeds may be set\");\n        }\n        else if (inputIds is not null)\n        {\n            batchSize = inputIds.IntShape()[0];\n            seqLength = inputIds.IntShape()[1];\n            inputsEmbeds = this.embed_tokens.forward(inputIds);\n            device = inputIds.device;\n        }\n        else if (inputsEmbeds is not null)\n        {\n            batchSize = inputsEmbeds.IntShape()[0];\n            seqLength = inputsEmbeds.IntShape()[1];\n            device = inputsEmbeds.device;\n        }\n        else\n        {\n            throw new ArgumentException(\"Either input_ids or inputs_embeds must be set\");\n        }","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.ML.GenAI.Mistral/MistralModel.cs#L52-L88","documentation":"MistralModel.forward, like LlamaModel, treats input_ids and inputs_embeds as mutually exclusive and throws ArgumentException if both are set. Providing both is ambiguous about which representation defines the sequence.","triggerScenarios":"Calling MistralModel.forward with an input where both InputIds and InputEmbeddings are non-null.","commonSituations":"Agent/pipeline code that sets embeddings but keeps token ids populated; custom prompt-building code that fills both fields defensively.","solutions":["Set only one of InputIds or InputEmbeddings before calling forward.","Clear InputIds when supplying embeddings (set to null).","Make the input construction code choose one representation explicitly."],"exampleFix":"// before\nvar input = new MistralModelInput { InputIds = ids, InputEmbeddings = embeds };\n// after\nvar input = new MistralModelInput { InputEmbeddings = embeds };","handlingStrategy":"validation","validationCode":"if (input.InputIds is not null && input.InputEmbeddings is not null) throw new ArgumentException(\"Set only one of InputIds or InputEmbeddings.\");","typeGuard":"bool HasAmbiguousInput(MistralModelInput i) => i.InputIds is not null && i.InputEmbeddings is not null;","tryCatchPattern":"try { output = model.forward(input); } catch (ArgumentException) { /* clear one field and retry */ }","preventionTips":["Pick one input representation per call site","Null out InputIds when passing embeddings","Cover both modes in tests"],"tags":["argument-validation","mistral","mutually-exclusive"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}