user3405: Let us say that I input a wrong move in Stockfish. What answer will Stockfish send me back? Or is there a function to check if a move is bad?
People, I found a solution by myself.

user2371: It doesn't seem Stockfish says anything. If it's illegal, it doesn't seem to accept it, and a suggestion is generated on a board without that move.
Illegal move
Position startpos moves e2e7 
Go 
Info depth 1 seldepth 1 score cp 72 nodes 28 nps 0 time 0 multipv 1 pv g1f3 
bestmove g1f3 ponder (none)
OK move
Position startpos moves e2e4 
Go
Info depth 1 seldepth 1 score cp 16 nodes 43 nps 43000 time 1 multipv 1 pv b8c6
bestmove b8c6 ponder (none)

user3405: I have found through self experimenting what was the best choice.
I send the pgn of the entire game each time. Then I send the pgn minus the last move. If they are the same, that means that the last move wasn't correct at all. If they aren't, the move is correct. This works because I use the same depth for both tries, and therefore the answer must be the same. Hope it helps!

user7281: Chess engines such as stockfish cannot be used to validates legal chess moves. It will crash or if you get lucky sometimes it won't. But go ahead whatever it is you are doing and good luck

user825: Sorry, I had to downvote your question, because you tried something that you weren't supposed to. Stockfish is a chess engine; it always and always assume a move given is legal. If you give it an illegal move, the behavior is undefined - from a crash to jumping king. Anything could happen if you give a move as illegal.
Nobody would use an engine to verify a move's legality. This is done by the GUI. You'll need to incorporate a move generator into your project.

user2130: Stockfish assumes that all FEN positions you feed it are legal positions. If you feed it an illegal position and ask it to evaluate it, it will likely crash:
Stockfish 5 64 by Tord Romstad, Marco Costalba and Joona Kiiski
position fen 4k3/4p3/8/8/8/8/8/3KP3
go depth 14
Segmentation fault: 11

But you could use a Python library such as Chessnut to validate moves. Chessnut returns all legal moves with get_moves() and raises an InvalidMove exception if you pass an illegal move to apply_move(), as shown in their example:
from Chessnut import Game

chessgame = Game()
print chessgame  # 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'

print chessgame.get_moves()
"""
['a2a3', 'a2a4', 'b2b3', 'b2b4', 'c2c3', 'c2c4', 'd2d3', 'd2d4', 'e2e3', 
 'e2e4', 'f2f3', 'f2f4', 'g2g3', 'g2g4', 'h2h3', 'h2h4', 'b1c3', 'b1a3', 
 'g1h3', 'g1f3']
"""

chessgame.apply_move('e2e4')  # succeeds!
print chessgame  # 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1'

chessgame.apply_move('e2e4')  # fails! (raises InvalidMove exception)

You could update the game each move with Chessnut, and only pass moves to Stockfish for evaluation if Chessnut says they're valid.

3405: <p>Let us say that I input a wrong move in Stockfish. What answer will Stockfish send me back? Or is there a function to check if a move is bad?</p>

<p>People, I found a solution by myself.</p>
 2371: <p>It doesn't seem Stockfish says anything. If it's illegal, it doesn't seem to accept it, and a suggestion is generated on a board without that move.</p>
<h3>Illegal move</h3>
<p>Position <strong>startpos moves e2e7</strong> <br/>
Go <br/>
Info depth 1 seldepth 1 score cp 72 nodes 28 nps 0 time 0 multipv 1 pv g1f3 <br/>
<strong>bestmove g1f3</strong> ponder (none)</p>
<h3>OK move</h3>
<p>Position <strong>startpos moves e2e4</strong> <br/>
Go
Info depth 1 seldepth 1 score cp 16 nodes 43 nps 43000 time 1 multipv 1 pv b8c6
<strong>bestmove b8c6</strong> ponder (none)</p>
 3405: <p>I have found through self experimenting what was the best choice.</p>

<p>I send the pgn of the entire game each time. Then I send the pgn minus the last move. If they are the same, that means that the last move wasn't correct at all. If they aren't, the move is correct. This works because I use the same depth for both tries, and therefore the answer must be the same. Hope it helps!</p>
 7281: <p>Chess engines such as stockfish cannot be used to validates legal chess moves. It will crash or if you get lucky sometimes it won't. But go ahead whatever it is you are doing and good luck</p>
 825: <p>Sorry, I had to downvote your question, because you tried something that you weren't supposed to. Stockfish is a chess engine; it always and always assume a move given is legal. If you give it an illegal move, the behavior is undefined - from a crash to jumping king. Anything could happen if you give a move as illegal.</p>

<p>Nobody would use an engine to verify a move's legality. This is done by the GUI. You'll need to incorporate a move generator into your project.</p>
 2130: <p>Stockfish assumes that all FEN positions you feed it are legal positions. If you feed it an <a href="http://www.chessvideos.tv/bimg/5rs712zf8j6g.png">illegal position</a> and ask it to evaluate it, it will likely crash:</p>

<pre><code>Stockfish 5 64 by Tord Romstad, Marco Costalba and Joona Kiiski
position fen 4k3/4p3/8/8/8/8/8/3KP3
go depth 14
Segmentation fault: 11
</code></pre>

<p>But you could use a Python library such as <a href="https://github.com/cgearhart/Chessnut">Chessnut</a> to validate moves. Chessnut returns all legal moves with <code>get_moves()</code> and raises an InvalidMove exception if you pass an illegal move to <code>apply_move()</code>, as shown in their example:</p>

<pre><code>from Chessnut import Game

chessgame = Game()
print chessgame  # 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1'

print chessgame.get_moves()
"""
['a2a3', 'a2a4', 'b2b3', 'b2b4', 'c2c3', 'c2c4', 'd2d3', 'd2d4', 'e2e3', 
 'e2e4', 'f2f3', 'f2f4', 'g2g3', 'g2g4', 'h2h3', 'h2h4', 'b1c3', 'b1a3', 
 'g1h3', 'g1f3']
"""

chessgame.apply_move('e2e4')  # succeeds!
print chessgame  # 'rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1'

chessgame.apply_move('e2e4')  # fails! (raises InvalidMove exception)
</code></pre>

<p>You could update the game each move with Chessnut, and only pass moves to Stockfish for evaluation if Chessnut says they're valid.</p>
